Matlab objects
[Runtime modules]

Objects can be defined in Matlab using the matlab module. Matlab classes are defined using the module GLM statement
module matlab::CLASSNAME; 
To define an object class in Matlab, you then refer to the class name, omitting the matlab:: module prefix of the name. The follow methods must be defined for each object used in an matlab module:

The constructor must be implemented as follows (replace CLASSNAME with the classes true name)

	function r = CLASSNAME(varargin)

	if (nargsin==0) % setup call from core
		% establish the pass configuration
		global passconfig;
		passconfig = 'PRETOPDOWN|BOTTOMUP|POSTTOPDOWN'; % omit those you don't need

		% create all your variables and assign them default values
		r.var1 = 1.23;
		r.var2 = 'Defaults set';
	else
		% create object directly from varargin (char must be supported)
	end

	% set the class
	r = class(r,'CLASSNAME');

	end	

The create method must be implemented as follows

	function r = create(my)

	% create your context-free initial values
	my.var1 = my.var1 + 0.11;
	my.var2 = 'Create done';

	r = my;
	end		

The init method must be implemented as follows

	function r = init(my,parent)

	% set your context-dependent values
	my.var1 = my.var1 + 0.11;
	my.var2 = 'Initialized';

	r = my;
	end	

The presync, sync, and postsync methods must be implemented and must be implemented if defined in passconfig. Implementation of {pre,post}sync is always as follows

	function [r t2] = sync(my,t0,t1) % define separate methods for each type of sync

	% update variables as appropriate
	my.var1 = my.var1+0.11;
	my.var2 = 'Sync';

	r = my;
	t2 = NEVER; % set t2 as appropriate (in seconds)
	end	

The char implementation is required by GridLAB-D's internal data conversion routines and must convert the object's data to a character string that can be embedded in GLM and XML files. The implementation must be as follows

	function s = char(my)
	
	s = sprintf('var1="%g kV"; var2="%s";',my.var1,my.var2); % adjust for your variables
	
	end	

The display implementation is necessary for Matlab's internal data conversion routines and must convert the object's data to a sequences of output lines that can be displayed on the screen. The implementation must be as follows

	function display(obj)

	disp(' ');
	% display your variables in gridlab debugger style 
	disp(['object ' inputname(1), ' {']);
	disp(['  var1 ' sprintf('%g',obj.var1) ' kV;']);
	disp(['  var2 "' obj.var2 '";']);
	disp('}');
	disp(' ');

	end	


GridLAB-DTM Version 2.0
An open-source project initiated by the US Department of Energy