Index: /issm/trunk/src/m/contrib/musselman/read_netCDF.m
===================================================================
--- /issm/trunk/src/m/contrib/musselman/read_netCDF.m	(revision 27873)
+++ /issm/trunk/src/m/contrib/musselman/read_netCDF.m	(revision 27874)
@@ -17,5 +17,5 @@
 
 function model_copy = read_netCDF(filename)
-    fprintf('NetCDF42C v1.1.12\n');
+    fprintf('NetCDF42C v1.1.13\n');
 
     % make a model framework to fill that is in the scope of this file
@@ -39,5 +39,4 @@
         catch
         end % 'results' group doesn't exist 
-
 
         % see if inversion is in there, if it is we may have to instantiate some classes
@@ -84,13 +83,14 @@
     global NCData;
     inversionGroup = netcdf.inqNcid(NCData, "inversion");
-    varid = netcdf.inqVarID(inversionGroup,'inversion_class_name')
+    varid = netcdf.inqVarID(inversionGroup, 'inversion_class_name');
     inversion_class = convertCharsToStrings(netcdf.getVar(inversionGroup, varid,'char'));
-    if inversion_class == 'm1qn3inversion'
+    if strcmp(inversion_class, 'm1qn3inversion')
         model_copy.inversion = m1qn3inversion();
         disp('Successfully created inversion class instance: m1qn3inversion')
-    elseif inversion_class == 'taoinversion'
+    elseif strcmp(inversion_class, 'taoinversion')
         model_copy.inversion = taoinversion();
         disp('Successfully created inversion class instance: taoinversion')
     else
+        disp('No inversion class was found')
     end
 end
@@ -109,8 +109,8 @@
         for variable = variables
             [varname, xtype, dimids, numatts] = netcdf.inqVar(group_location_in_file, variable);
-            %disp(varname)
             copy_variable_data_to_new_model(group_location_in_file,varname, xtype);
         end
-    catch
+    catch ME
+        rethrow(ME)
     end
 
@@ -141,36 +141,56 @@
     global NCData;
     %disp(varname)
-    % putting try/catch here so that any errors generated while copying data are logged and not lost by the try/catch in walk_nested_groups
-    try
-        %disp(netcdf.inqGrpNameFull(group_location_in_file))
-        %disp(class(netcdf.inqGrpNameFull(group_location_in_file)))
-        adress_to_attr = strrep(netcdf.inqGrpNameFull(group_location_in_file), '/', '.');
-        % netcdf uses Row Major Order but MATLAB uses Column Major Order so we need to transpose all arrays w/ more than 1 dim
-        data = netcdf.getVar(group_location_in_file, netcdf.inqVarID(group_location_in_file, varname));
-        
-        if all(size(data)~=1)
-            data = data.';
+    % this is an inversion band-aid
+    if strcmp(varname, 'inversion_class_name')
+        % we don't need this
+    else
+        % putting try/catch here so that any errors generated while copying data are logged and not lost by the try/catch in walk_nested_groups function
+        try
+            %disp(netcdf.inqGrpNameFull(group_location_in_file))
+            %disp(class(netcdf.inqGrpNameFull(group_location_in_file)))
+            adress_to_attr = strrep(netcdf.inqGrpNameFull(group_location_in_file), '/', '.');
+            
+            data = netcdf.getVar(group_location_in_file, netcdf.inqVarID(group_location_in_file, varname));
+            
+    
+            % matlab needs to know that ' ' = char()
+            if xtype == 2 && isempty(all(data))
+                data = cell(char());
+            elseif numel(data) == 1 && xtype == 3 && data == -32767
+                data = cell(char());
+            end
+            % band-aid for cell-char-arrays:
+            if xtype == 2 && strcmp(data, 'default')
+                data = {'default'};
+            end
+            
+            % netcdf uses Row Major Order but MATLAB uses Column Major Order so we need to transpose all arrays w/ more than 1 dim
+            if all(size(data)~=1) || xtype == 2
+                data = data.';
+            end
+            
+            % the issm c compiler does not work with int64 datatypes, so we need to convert those to int16
+            % reference this (very hard to find) link for netcdf4 datatypes: https://docs.unidata.ucar.edu/netcdf-c/current/netcdf_8h_source.html
+            %xtype
+            if xtype == 10
+                arg_to_eval = ['model_copy', adress_to_attr, '.', varname, ' = ' , 'double(data);'];
+                eval(arg_to_eval);
+                %disp('saved int64 as int16')
+            else
+                arg_to_eval = ['model_copy', adress_to_attr, '.', varname, ' = ' , 'data;'];
+                eval(arg_to_eval);
+            end
+            
+            full_addy = netcdf.inqGrpNameFull(group_location_in_file);
+            %disp(xtype)
+            %class(data)
+            fprintf('Successfully saved %s to %s\n', varname, full_addy);
+        catch e %e is an MException struct
+            fprintf(1,'There was an error with %s! \n', varname)
+            fprintf('The message was:\n%s\n',e.message);
+            fprintf(1,'The identifier was:\n%s\n',e.identifier);
+            disp()
+            % more error handling...
         end
-        
-        % the issm c compiler does not work with int64 datatypes, so we need to convert those to int16
-        % reference this (very hard to find) link for netcdf4 datatypes: https://docs.unidata.ucar.edu/netcdf-c/current/netcdf_8h_source.html
-        %xtype
-        if xtype == 10
-            arg_to_eval = ['model_copy', adress_to_attr, '.', varname, ' = ' , 'double(data);'];
-            eval(arg_to_eval);
-            %disp('saved int64 as int16')
-        else
-            arg_to_eval = ['model_copy', adress_to_attr, '.', varname, ' = ' , 'data;'];
-            eval(arg_to_eval);
-        end
-        
-        full_addy = netcdf.inqGrpNameFull(group_location_in_file);
-        %disp(xtype)
-        %class(data)
-        fprintf('Successfully saved %s to %s\n', varname, full_addy);
-    catch e %e is an MException struct
-        fprintf(1,'The identifier was:\n%s',e.identifier);
-        fprintf(1,'There was an error! The message was:\n%s',e.message);
-        % more error handling...
     end
 end
Index: /issm/trunk/src/m/contrib/musselman/read_netCDF_commit.py
===================================================================
--- /issm/trunk/src/m/contrib/musselman/read_netCDF_commit.py	(revision 27873)
+++ /issm/trunk/src/m/contrib/musselman/read_netCDF_commit.py	(revision 27874)
@@ -24,5 +24,5 @@
 
 def read_netCDF(filename):
-    print('NetCDF42C v1.1.12')
+    print('NetCDF42C v1.1.13')
 
     # check if path exists
@@ -54,8 +54,12 @@
     # walk through each group looking for subgroups and variables
     for group in NCData.groups.keys():
-        # have to send a custom name to this function: filename.groups['group']
-        name = "NCData.groups['" + str(group) + "']"
-        walk_nested_groups(name)
+        if 'debris' in group:
+            pass
+        else:
+            # have to send a custom name to this function: filename.groups['group']
+            name = "NCData.groups['" + str(group) + "']"
+            walk_nested_groups(name)
     
+    print("Model Successfully Recreated.")
     return model_copy
 
@@ -116,4 +120,7 @@
     if str(location_of_variable_in_model + '.' + variable_name) =='results.solutionstep':
         pass
+    # qmu band-aid
+    elif 'qmu.statistics.method' in str(location_of_variable_in_model + '.' + variable_name):
+        pass
     # handle any strings:
     elif 'char' in eval(location_of_variable_in_file + '.dimensions[0]'):
@@ -151,2 +158,22 @@
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: /issm/trunk/src/m/contrib/musselman/write_netCDF.m
===================================================================
--- /issm/trunk/src/m/contrib/musselman/write_netCDF.m	(revision 27873)
+++ /issm/trunk/src/m/contrib/musselman/write_netCDF.m	(revision 27874)
@@ -11,5 +11,5 @@
 
 function write_netCDF(model_var, filename)
-    disp('MATLAB C2NetCDF4 v1.1.12');
+    disp('MATLAB C2NetCDF4 v1.1.13');
     % model_var = class object to be saved
     % filename = path and name to save file under
@@ -30,5 +30,5 @@
     try
         % if results had meaningful data, save the name of the subclass and class instance
-        NetCDF.groups('results');
+        netcdf.inqNcid(NetCDF,'results');
         results_subclasses_bandaid(model_var);
         % otherwise, ignore
@@ -41,35 +41,49 @@
 
 
+
 function make_NetCDF(filename)
+    % matlab can't handle input in the jupyter interface, so we just yell at the user to rename
+    % their file if needed
     % If file already exists delete / rename it
     if exist(filename, 'file') == 2
         fprintf('File %s already exists\n', filename);
+        disp('Please rename your file.')
+        return
     
         % If so, inquire for a new name or to delete the existing file
-        newname = input('Give a new name or input "delete" to replace: ', 's');
-
-        if strcmpi(newname, 'delete')
-            delete(filename);
-        else
-            fprintf('New file name is %s\n', newname);
-            filename = newname;
-        end
-    end
-    % Otherwise create the file and define it globally so other functions can call it
-    global NetCDF;
-    NetCDF = netcdf.create(filename, 'NETCDF4');
-    netcdf.putAtt(NetCDF, netcdf.getConstant('NC_GLOBAL'), 'history', ['Created ', datestr(now)]);
-    netcdf.defDim(NetCDF, 'Unlim', netcdf.getConstant('NC_UNLIMITED')); % unlimited dimension
-    netcdf.defDim(NetCDF, 'float', 1);     % single integer dimension
-    netcdf.defDim(NetCDF, 'int', 1);       % single float dimension
-    
-
-    fprintf('Successfully created %s\n', filename);
-end
-
+        %newname = input('Give a new name or input "delete" to replace: ', 's');
+
+        %if strcmpi(newname, 'delete')
+            %delete filename;
+        %else
+            %fprintf('New file name is %s\n', newname);
+            %filename = newname;
+        %end
+    else
+        % Otherwise create the file and define it globally so other functions can call it
+        global NetCDF;
+        NetCDF = netcdf.create(filename, 'NETCDF4');
+        netcdf.putAtt(NetCDF, netcdf.getConstant('NC_GLOBAL'), 'history', ['Created ', datestr(now)]);
+        netcdf.defDim(NetCDF, 'Unlim', netcdf.getConstant('NC_UNLIMITED')); % unlimited dimension
+        netcdf.defDim(NetCDF, 'float', 1);     % single integer dimension
+        netcdf.defDim(NetCDF, 'int', 1);       % single float dimension
+    
+        fprintf('Successfully created %s\n', filename);
+    end
+end
+
+
+%{
+    Since python uses subclass instances and MATLAB uses fields, we need to guess which subclass instance python will need
+    given the name of the sub-field in MATLAB. We make this guess based on the name of the MATLAB subfield that will contain
+    the name of the python subclass instance. For example, md.results.StressbalanceSolution is an subfield in MATLAB,
+    but a class instance of solution(). Notice that StressbalanceSolution contains the name "Solution" in it. This is what
+    we will save to the netCDF file for python to pick up.
+%}
 
 function 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
+    global NetCDF;
+    % The results class may have nested fields within it, so we need to record the name of 
+    % the nested field as it appears in the model that we're trying to save
     quality_control = {};
     
@@ -86,21 +100,23 @@
         class_instance_name = class_instance_names{i};
         
-        % Check to 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 isa(results_var.(class_instance_name), 'solutionstep')
+        if contains(class_instance_name, 'solutionstep',IgnoreCase=true)
             quality_control{end+1} = 1;
-            write_string_to_netcdf('variable_name', 'solutionstep', 'address_of_child', class_instance_name, 'group', groupid);
+            write_string_to_netcdf('solutionstep', class_instance_name, groupid);
+            disp('Successfully stored class python subclass instance: solutionstep')
         end
         
         % Check to see if there is a solution class instance
-        if isa(results_var.(class_instance_name), 'solution')
+        if contains(class_instance_name, 'solution',IgnoreCase=true)
             quality_control{end+1} = 1;
-            write_string_to_netcdf('variable_name', 'solution', 'address_of_child', class_instance_name, 'group', groupid);
+            write_string_to_netcdf('solution', class_instance_name, groupid);
+            disp('Successfully stored class python subclass instance: solution')
         end
         
         % Check to see if there is a resultsdakota class instance
-        if isa(results_var.(class_instance_name), 'resultsdakota')
+        if contains(class_instance_name, 'resultsdakota',IgnoreCase=true)
             quality_control{end+1} = 1;
-            write_string_to_netcdf('variable_name', 'resultsdakota', 'address_of_child', class_instance_name, 'group', groupid);
+            write_string_to_netcdf('resultsdakota', class_instance_name, groupid);
+            disp('Successfully stored class python subclass instance: resultsdakota')
         end
     end
@@ -137,8 +153,18 @@
     % model_subclass is an object (ie, md.mesh.elements)
     % list_of_layers is a cell array of subclasses/attributes/fields so that we can copy the structure into netcdf (ie, {'mesh', 'elements'})
-    % Use try/except since model_subclass is either a subclass w/ fields or it's not, no unknown exceptions
+    % need to check if inversion or m1qn3inversion or taoinversion class
+    if numel(given_list_of_layers) == 1
+        if strcmp(given_list_of_layers{1}, 'inversion')
+            create_group(model_subclass, given_list_of_layers);
+            check_inversion_class(model_subclass);
+        end
+    end
+    
+    % Use try/except since model_subclass is either a subclass/struct w/ props/fields or it's not, no unknown exceptions
     try 
         % look for children - this is where the catch would be called
         children = fieldnames(model_subclass);
+
+        % if there are children, loop through them and see if we need to save any data
         for child = 1:numel(children)
             % record our current location
@@ -151,23 +177,65 @@
             
             % if the empty model does not have this attribute, it's because it's new so we save it to netcdf
-            try
-                location_of_child_in_empty_model = empty_model_subclass.(current_child);
-            catch
-                % empty model didn't have the attr, so we save it to netcdf
-                create_group(location_of_child, list_of_layers);
-            end
-            
-            % if the current attribute is a numerical array assume it has valuable data that needs to be saved
-            if isnumeric(location_of_child) && logical(numel(location_of_child) > 1)
-                create_group(location_of_child, list_of_layers);
-                % i don't think I need this line but it's in my python code...
-                % walk_through_subclasses(location_of_child)
-            % if the attributes are identical we don't need to save anything
-            elseif (all(isnan(location_of_child)) && all(isnan(location_of_child_in_empty_model))) || isempty(setxor(location_of_child, location_of_child_in_empty_model))
-                walk_through_subclasses(location_of_child, location_of_child_in_empty_model, list_of_layers);
-            % if the attributes are not the same we need to save ours
-            else
-                create_group(location_of_child, list_of_layers);
-                walk_through_subclasses(location_of_child, location_of_child_in_empty_model, list_of_layers);
+            % there are 2 cases: the location is a struct, the location is a class
+            if isstruct(model_subclass)
+                % this would mean that the layer above the layer we're interested in is a struct, so
+                % we can navigate our empty model as such
+                if isfield(empty_model_subclass, current_child)
+                    % the layer we're interested in does exist, we just need to compare states
+                    location_of_child_in_empty_model = empty_model_subclass.(current_child);
+                    % if the current attribute is a numerical array assume it has valuable data that needs to be saved
+                    if isnumeric(location_of_child) && logical(numel(location_of_child) > 1)
+                        create_group(location_of_child, list_of_layers);
+                    % if the attributes are identical we don't need to save anything
+                    elseif (all(isnan(location_of_child)) && all(isnan(location_of_child_in_empty_model))) || isempty(setxor(location_of_child, location_of_child_in_empty_model))
+                        walk_through_subclasses(location_of_child, location_of_child_in_empty_model, list_of_layers);
+                    % if the attributes are not the same we need to save ours
+                    else
+                        % THE ORDER OF THESE LINES IS CRITICAL
+                        walk_through_subclasses(location_of_child, location_of_child_in_empty_model, list_of_layers);
+                        create_group(location_of_child, list_of_layers);
+                    end
+                % this would mean that the layer we're interested in is not fundamental to the model architecture
+                % and thus needs to be saved to the netcdf
+                else
+                    walk_through_subclasses(location_of_child, empty_model_subclass, list_of_layers);
+                    create_group(location_of_child, list_of_layers);
+                end
+            % this would mean it's not a struct, and must be a class/subclass
+            % we now check the state of the class property
+            else 
+                try
+                    if isprop(empty_model_subclass, current_child)
+                        % the layer we're interested in does exist, we just need to compare states
+                        location_of_child_in_empty_model = empty_model_subclass.(current_child);
+                        % if the current attribute is a numerical array assume it has valuable data that needs to be saved
+                        if isnumeric(location_of_child) && logical(numel(location_of_child) > 1)
+                            create_group(location_of_child, list_of_layers);
+                        
+                        elseif iscell(location_of_child)
+                            % if the attributes are identical we don't need to save anything
+                            if isempty(setxor(location_of_child, location_of_child_in_empty_model))
+                                % pass
+                            else
+                            % otherwise we need to save
+                                walk_through_subclasses(location_of_child, empty_model_subclass, list_of_layers);
+                                create_group(location_of_child, list_of_layers);
+                            end
+                        elseif (all(isnan(location_of_child)) && all(isnan(location_of_child_in_empty_model)))
+                            walk_through_subclasses(location_of_child, location_of_child_in_empty_model, list_of_layers);
+                        % if the attributes are not the same we need to save ours
+                        else
+                            % THE ORDER OF THESE LINES IS CRITICAL
+                            walk_through_subclasses(location_of_child, location_of_child_in_empty_model, list_of_layers);
+                            create_group(location_of_child, list_of_layers);
+                        end
+                    else
+                        walk_through_subclasses(location_of_child, empty_model_subclass, list_of_layers);
+                        create_group(location_of_child, list_of_layers);
+                    end
+                catch
+                    walk_through_subclasses(location_of_child, empty_model_subclass, list_of_layers);
+                    create_group(location_of_child, list_of_layers);
+                end
             end
         end
@@ -175,8 +243,13 @@
         % If the caught error is a fieldname error, it's just saying that a variable has no fields and thus can be ignored
         if strcmp(ME.identifier, 'MATLAB:fieldnames:InvalidInput')
+            % do nothing
         % this is if we come accross instances/subfields in our model that are not fundamental to the model class (ie, taoinversion)
         elseif strcmp(ME.identifier, 'MATLAB:UndefinedFunction')
+            walk_through_subclasses(location_of_child, empty_model_subclass, given_list_of_layers);
+            create_group(location_of_child, list_of_layers);
         % If it's a different error, rethrow it to MATLAB's default error handling
         else
+            disp(ME.identifier)
+            disp(given_list_of_layers)
             rethrow(ME);
         end
@@ -196,15 +269,12 @@
         group = netcdf.defGrp(NetCDF, group_name);
     catch % group was already made
-        group = netcdf.inqNcid(NetCDF, group_name);
-    end
-    % need to check if inversion or m1qn3inversion or taoinversion class
-    if strcmp(group_name, 'inversion')
-        check_inversion_class(location_of_child);
-    end
-    
+        group = netcdf.inqNcid(NetCDF, group_name);    
+    end
+
     % if the data is nested, create nested groups to match class structure
     if numel(list_of_layers) > 2
-        for name = list_of_layers{2:end-1}
-            % again, the group levels may have already been made
+        % the string() method is really important here since matlab apparently can't handle the infinite complexity of a string without the string method.
+        for name = string(list_of_layers(2:end-1))
+            % the group levels may have already been made
             try % group hasn't been made
                 group = netcdf.defGrp(group, name);
@@ -214,13 +284,21 @@
         end
     end
-
-    % Lastly, handle the variable(s)
-    variable_name = list_of_layers{end};
-    create_var(variable_name, location_of_child, group);
-    
-end
-
-
-
+    % if the object is not a variable, we have nothing to save
+    try
+        % if this line works, we're still dealing with a struct and need lower levels
+        if isempty(fieldnames(location_of_child))
+            % do nothing
+        end
+    catch
+        % if that line doesn't work, it means we're dealing with data
+        % Lastly, handle the variable(s)
+        variable_name = list_of_layers{end};
+        create_var(variable_name, location_of_child, group);
+    end
+end
+
+
+% ironically inversion does not have the same problem as results as inversion subfields
+% are actually subclasses and not fields
 function check_inversion_class(model_var)
     global NetCDF;
@@ -229,4 +307,5 @@
     % Check if the function has already been executed
     if isempty(executed)
+        disp('Deconstructing Inversion class instance')
         % Need to make sure that we have the right inversion class: inversion, m1qn3inversion, taoinversion
         groupid = netcdf.inqNcid(NetCDF,'inversion');
@@ -234,19 +313,15 @@
         if isa(model_var, 'm1qn3inversion')
             write_string_to_netcdf('inversion_class_name', 'm1qn3inversion', groupid);
-            disp('Successfully saved inversion class instance m1qn3inversion');
+            disp('Successfully saved inversion class instance m1qn3inversion')
         elseif isa(model_var, 'taoinversion')
             write_string_to_netcdf('inversion_class_name', 'taoinversion', groupid);
-            disp('Successfully saved inversion class instance taoinversion');
+            disp('Successfully saved inversion class instance taoinversion')
         else
             write_string_to_netcdf('inversion_class_name', 'inversion', groupid);
-            disp('Successfully saved inversion class instance inversion');
+            disp('Successfully saved inversion class instance inversion')
         end
         % Set the persistent variable to indicate that the function has been executed
         executed = true;
-    else
-        % Code to skip execution if the function has already run
-    end
-
-
+    end
 end
 
@@ -265,41 +340,46 @@
     if any(size(address_of_child)>1) && ~ischar(address_of_child)
         write_numeric_array_to_netcdf(variable_name, address_of_child, group);
-    
-    % check if it's an int
-    elseif mod(address_of_child,1) == 0 || isinteger(address_of_child) && numel(address_of_child) == 1
+
+    % check if it's a string
+    elseif ischar(address_of_child)
+        write_string_to_netcdf(variable_name, address_of_child, group);
+
+    % or an empty variable
+    elseif isempty(address_of_child)
+        variable = netcdf.defVar(group, variable_name, "NC_DOUBLE", intdim);
+
+    % or a list of strings -- this needs work as it can only handle a list of 1 string
+    elseif iscell(address_of_child) && ischar(address_of_child{1})
+        for i = 1:numel(address_of_child)
+            write_string_to_netcdf(variable_name, address_of_child{i}, group, true);
+        end
+        
+    % or an empty list
+    elseif iscell(address_of_child) && isempty(address_of_child) || isa(address_of_child, 'double') && isempty(address_of_child)
         variable = netcdf.defVar(group, variable_name, "NC_INT", intdim);
+        netcdf.putVar(group,variable, -32767);
+
+    % or a bool
+    elseif islogical(address_of_child)
+        % netcdf4 can't handle bool types like true/false so we convert all to int 1/0 and add an attribute named units with value 'bool'
+        variable = netcdf.defVar(group, variable_name, 'NC_SHORT', intdim);
+        netcdf.putVar(group,variable,int8(address_of_child));
+        % make sure other systems can flag the bool type
+        netcdf.putAtt(group,variable,'units','bool');
+
+    % or a regular list
+    elseif iscell(address_of_child)
+        disp('made list w/ unlim dim')
+        variable = netcdf.defVar(group, variable_name, "NC_DOUBLE", unlimdim);
         netcdf.putVar(group,variable,address_of_child);
-    
+        
     % or a float
     elseif isfloat(address_of_child) && numel(address_of_child) == 1
         variable = netcdf.defVar(group, variable_name, "NC_DOUBLE", floatdim);
         netcdf.putVar(group,variable,address_of_child);
-
-    % or a string
-    elseif ischar(address_of_child)
-        write_string_to_netcdf(variable_name, address_of_child, group);
-
-    % or a bool
-    elseif islogical(address_of_child)
-        % netcdf4 can't handle bool types like true/false so we convert all to int 1/0 and add an attribute named units with value 'bool'
-        variable = netcdf.defVar(group, variable_name, 'NC_SHORT', 'int');
-        netcdf.putVar(group,variable,logical(address_of_child));
-        % make sure other systems can flag the bool type
-        netcdf.putAtt(group,variable,'units','bool');
-        
-    % or an empty list
-    elseif iscell(address_of_child) && isempty(address_of_child) || isa(address_of_child, 'double') && isempty(address_of_child)
+        
+    % or a int
+    elseif mod(address_of_child,1) == 0 || isinteger(address_of_child) && numel(address_of_child) == 1
         variable = netcdf.defVar(group, variable_name, "NC_SHORT", intdim);
-
-    % or a list of strings -- this needs work as it can only handle a list of 1 string
-    elseif iscell(address_of_child) && ischar(address_of_child{1})
-        for i = 1:numel(address_of_child)
-            write_string_to_netcdf(variable_name, address_of_child{i}, group, list = true);
-        end
-
-    % or a regular list
-    elseif iscell(address_of_child)
-        disp('made list w/ unlim dim')
-        variable = netcdf.defVar(group, variable_name, "NC_DOUBLE", unlimdim);
         netcdf.putVar(group,variable,address_of_child);
 
@@ -331,27 +411,39 @@
     the_string_to_save = address_of_child;
 
-    % convert string to 
-    uint_method=uint8(the_string_to_save);
-    method_ID = char(uint_method);
-    length_of_the_string = numel(method_ID);
-    
-    % Convert the string to character data using string array
-    %str_out = char(the_string_to_save)
-
-    % Determine the length of the string
-    %length_of_the_string = numel(str_out)
-
-    % Check if the dimension already exists, and if not, create it
-    name_of_dimension = ['char', num2str(length_of_the_string)];
-    try
-        dimID = netcdf.defDim(group, name_of_dimension, length_of_the_string);
-    catch
-        dimID = netcdf.inqDimID(group, name_of_dimension);
-    end
-    % Now we can make a variable in this dimension:
-    string_var = netcdf.defVar(group, variable_name, "NC_CHAR", [dimID]);
-    
-    % Finally, we can write the variable:
-    netcdf.putVar(group, string_var, method_ID);
+    if isempty(the_string_to_save)
+        % if the char array is empty, save an empty char
+        name_of_dimension = ['char', num2str(0)];
+        try
+            dimID = netcdf.defDim(group, name_of_dimension, 0);
+        catch
+            dimID = netcdf.inqDimID(group, name_of_dimension);
+        end
+        % Now we can make a variable in this dimension:
+        string_var = netcdf.defVar(group, variable_name, "NC_CHAR", [dimID]);
+        % we leave empty now
+    else
+        % convert string to 
+        uint_method=uint8(the_string_to_save).';
+        method_ID = char(uint_method);
+        length_of_the_string = numel(method_ID);
+        
+        % Convert the string to character data using string array
+        %str_out = char(the_string_to_save)
+    
+        % Determine the length of the string
+        %length_of_the_string = numel(str_out)
+    
+        % Check if the dimension already exists, and if not, create it
+        name_of_dimension = ['char', num2str(length_of_the_string)];
+        try
+            dimID = netcdf.defDim(group, name_of_dimension, length_of_the_string);
+        catch
+            dimID = netcdf.inqDimID(group, name_of_dimension);
+        end
+        % Now we can make a variable in this dimension:
+        string_var = netcdf.defVar(group, variable_name, "NC_CHAR", [dimID]);
+        % Finally, we can write the variable (always transpose for matlab):
+        netcdf.putVar(group, string_var, method_ID);
+    end
 
     disp(['Successfully transferred data from ', variable_name, ' to the NetCDF']);
@@ -463,3 +555,2 @@
     end
 end
-
Index: /issm/trunk/src/m/contrib/musselman/write_netCDF_commit.py
===================================================================
--- /issm/trunk/src/m/contrib/musselman/write_netCDF_commit.py	(revision 27873)
+++ /issm/trunk/src/m/contrib/musselman/write_netCDF_commit.py	(revision 27874)
@@ -24,5 +24,5 @@
 
 def write_netCDF(model_var, model_name: str, filename: str):
-    print('C2NetCDF4 v1.1.12')
+    print('Python C2NetCDF4 v1.1.12')
     '''
     model_var = class object to be saved
@@ -90,5 +90,5 @@
     
         # If so, inqure for a new name or to do delete the existing file
-        newname = input('Give a new name or input "delete" to replace: ')
+        newname = input('Give a new name or "delete" to replace: ')
 
         if newname == 'delete':
@@ -134,8 +134,8 @@
             # in the framework of an empty model. If this is the case, we move to the except statement
             try:
-                # if the variable is an array, assume it has relevant data
+                # if the variable is an array, assume it has relevant data (this is because the next line cannot evaluate "==" with an array)
                 if isinstance(eval(adress_of_child), np.ndarray):
                     create_group(model_var, adress_of_child)
-                    walk_through_subclasses(model_var, adress_of_child, model_name)
+                # if the attributes are identical we don't need to save anything
                 elif eval(adress_of_child) == eval(adress_of_child_in_empty_class):
                     walk_through_subclasses(model_var, adress_of_child, model_name)
@@ -144,7 +144,9 @@
                     create_group(model_var, adress_of_child)
                     walk_through_subclasses(model_var, adress_of_child, model_name)
+            # AttributeError since the empty_model wouldn't have the same attribute as our model
             except AttributeError:
+                # THE ORDER OF THESE LINES IS CRITICAL
+                walk_through_subclasses(model_var, adress_of_child, model_name)
                 create_group(model_var, adress_of_child)
-                walk_through_subclasses(model_var, adress_of_child, model_name)
     except AttributeError: pass
     except Exception as e: print(e)
@@ -166,5 +168,5 @@
 
     # if the data is nested, create nested groups to match class structure
-    if len(levels_of_class) > 3:
+    if len(levels_of_class) > 2:
         for name in levels_of_class[2:-1]:
             group = group.createGroup(str(name))
@@ -349,2 +351,35 @@
             # write the variable:
             variable[:] = eval(adress_of_child)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
