
% In this section you may modify the mesh in any way that does not
% alter the set of nodes.

    if (Steps(m)==0) && m.globalDynamicProps.doinit  % Initialisation code.
        % Put any code here that should only be performed at the start of
        % the simulation, for example, to set up initial morphogen values.
        
        % m.nodes is the set of vertex positions, an N by 3 array if there
        % are N vertices.  Row number K contains the X, Y, and Z
        % coordinates of the Kth vertex. To obtain a list of the X
        % coordinates of every vertex, write m.nodes(:,1).  The Y
        % coordinates are given by m.nodes(:,2) and the Z coordinates by
        % m.nodes(:,3).

        % Set up a morphogen promoter (_p suffix) region where x values are minimum
        % id_prox_p(m.nodes(:,1)==min(m.nodes(:,1)))=1;
        % if the morphogen level (_l suffix) is to be used in this iteration 
        % set the level using the morphogen activity (_a suffix).
        % id_prox_l=id_prox_p * id_prox_a; % when a mutation is specified in the GUI 
        % the activity (_a) is set to zero

        % One way to set up a morphogen gradient is by ...
        % Setting up a gradient by clamping the ends (execute only once)
        % P=id_prox_p;
        % m.morphogenclamp( ((id_prox_p==1)|(id_dist_p==1)), polariser_i ) = 1;
        % m = leaf_mgen_conductivity( m, 'POLARISER', 0.01 );  %specifies the diffusion rate of polariser    
        % m = leaf_mgen_absorption( m, 'POLARISER', 0.1 );     % specifies degradation rate of polariser

        % Fixing vertices, i.e. fix z for the base to prevent base from moving up or down
        % m=leaf_fix_vertex(m,'vertex',find(id_prox_p==1),'dfs','z');

        % To cut the mesh, set a temporary morphogen to 1 in places to cut
        % seams=zeros(size(P));
        % seams(indexes to places to cut)=1;
        % m=leaf_set_seams(m,seams);

    end
    
    % Second way to generate a gradient
    % generating (+) and sinking (-) a diffusing signal (in this case polariser)
    % m.mgen_production( :, polariser_i ) = + 5*s_spur_p - P .* id_dist_p;

    % Monitor growth by scattering discs that deform over time (c.f. inducing biological clones)
    % (CARE - if the canvas is flat ensure that Plot:Hide Thickness is true, 
    % because a quirk of the Matlab z-buffer means that they can get hidden by mistake)
    %    if (340>realtime-dt) && (340<realtime+dt) % discs to be added at realtime==340
    %        m = leaf_makesecondlayer( m, ...  % This function adds discs that represent transformed cells.
    %            'mode', 'each', ...  % Make discs randomly scattered over the canvas.
    %            'relarea', 1/16000, ...   % Each discs has area was 1/16000 of the initial area of the canvas.
    %            'probpervx', 'V_FLOWER', ... % induce discs over whole canvas (V_FLOWER is 1 over whole canvas)
    %            'numcells',4500,...%number of discs (that will become ellipses)
    %            'sides', 6, ...  % Each discs is approximated as a 6-sided regular polygon.
    %            'colors', [0.5 0.5 0.5], ...  % Default colour is gray but
    %            'colorvariation',1,... % Each disc is a random colour
    %            'add', true );  % These discs are added to any discs existing already
    %    end
    
    % Directives for creating latex representation directly from Matlab code
    % not fully implemented yet but will use @@ directives
    % @@at t
    % @@before t
    % @@after t
    % @@between t1 t2

%     % If you want to define different phases according to the absolute
%     % time, create a morphogen for each phase and modulate 
%     % expressions using the morphogen
%     % like.  For example:
%     if (realtime < 10)  % first growth phase
%         f_firstgrowth_p = 1;
%     else
%         f_firstgrowth_p = 0;
%     end
%     if (realtime >= 10) % second growth phase
%         f_secondgrowth_p = 1;
%     else
%         f_secondgrowth_p = 0;
%     end
%
%     % If you want one morphogen to affect others only during a certain
%     % phase, write something like:
%
%     mgen_a_p = f_firstgrowth_p .* (various terms); % will zero except in firstgrowth

    % Code common to all models.
    % @@PRN Polariser Regulatory Network
        % Every equation to be formatted should end with an at-at Eqn N comment.
    % @@GRN Gene Regulatory Network
        % Every equation to be formatted should end with an at-at Eqn N comment.
    % @@KRN Growth Regulatory Network
        % Every equation to be formatted should end with an at-at Eqn N comment.

    % Code for specific models.
    switch modelname
        case 'MODEL1'  % @@model MODEL1
            % @@PRN Polariser Regulatory Network
                % Every equation to be formatted should end with an at-at Eqn N comment.
                % P(:) = ...  % @@ Eqn xx
            % @@GRN Gene Regulatory Network
                % Every equation to be formatted should end with an at-at Eqn N comment.
            % @@KRN Growth Regulatory Network
                % Every equation to be formatted should end with an at-at Eqn N comment.
                % kapar_p(:) = 0;  % @@ Eqn xx
                % kaper_p(:) = 0;  % @@ Eqn xx
                % kbpar_p(:) = 0;  % @@ Eqn xx
                % kbper_p(:) = 0;  % @@ Eqn xx
                % knor_p(:)  = 0;  % @@ Eqn xx
        case 'MODEL2'  % @@model MODEL2
            % @@PRN Polariser Regulatory Network
                % Every equation to be formatted should end with an at-at Eqn N comment.
                % P(:) = ...  % @@ Eqn xx
            % @@GRN Gene Regulatory Network
                % Every equation to be formatted should end with an at-at Eqn N comment.
            % @@KRN Growth Regulatory Network
                % Every equation to be formatted should end with an at-at Eqn N comment.
                % kapar_p(:) = 0;  % @@ Eqn xx
                % kaper_p(:) = 0;  % @@ Eqn xx
                % kbpar_p(:) = 0;  % @@ Eqn xx
                % kbper_p(:) = 0;  % @@ Eqn xx
                % knor_p(:)  = 0;  % @@ Eqn xx
        otherwise
            % If this happens, maybe you forgot a model.
    end
