
    % The following are regular expressions
    % At
    % From time
    % Eqn 
    % an isolated ellipsis ...
        
    % Factors are given the following prefixes:
    % ID for identity factor
    % S for signalling factor (most are used only in the set up phase)
    % V for visualation factors (only used for visualisation purposes)
    % F for finite element manipulations

    % NOTE all steps prior to 250hrs are considered as part of the set up
    % phase.


    disp(sprintf('mutant state cyc=%d dich=%d div=%d cenorg=%d dichdistor=%d',...
        id_cyc_a,id_dich_a,id_div_a,id_cenorg_a,v_dichdistorg_a))
    OLD_DIFFUSION = false;
    HOURS_PER_PLASTOCHRON = 10;
    SPACERESCALE = 4;
    pd_offset=0;

    if realtime<340
        id_late_p(:)=0;
        id_early_p(:)=1;
    else
        id_late_p(:)=1;
        id_early_p(:)=0;
    end

    %INITIALISATION
    if realtime==22*HOURS_PER_PLASTOCHRON %23*HOURS_PER_PLASTOCHRON
        m.userdata.all_regions_ready=false; % controls dynamic subdivision
        m.userdata.donesubdivisions=false;
        m.userdata.extra_regions_ready=false;
        fprintf( 1, 'Zeroing morphogens at step %d, time %.3f.\n', ...
            Steps(m), realtime );
        m.morphogens=zeros(size(m.morphogens));
        m.mgen_production(:)=0;
        fprintf( 1, 'Initialising morphogens at step %d, time %.3f.\n', ...
            Steps(m), realtime );

        % First assign factors to regions (vertices) in the finite elements
        % mesh. These are shown in Figures 5 and 6.
        %
        % v_theta is the angle around the z axis.  This is for visualisation
        % purposes and does not model a biological morphogen.
        v_theta_p = atan2( m.nodes(:,2), m.nodes(:,1) )*(0.5/pi);

        % Find all the nodes at the base of the initial flower shape,
        % i.e. those whose z
        % coordinate is less than -0.5/SPACERESCALE.  Set the id_prox morphogen to be 1
        % there.  Since id_prox does not diffuse and is not absorbed, the
        % values set here persist unchanged during development.
        basenodes = m.nodes(:,3) < -0.1801;

        % Find the inner base nodes: those whose radius in the XY plane is
        % less than the maximum.
        xy = m.nodes(:,[1 2]);
        radiisq = sum(xy.*xy,2);
        maxrsq = max(radiisq);
        innerbasenodes = radiisq < 0.20*0.99;
        m.userdata.innerbasenodes=innerbasenodes;

        id_prox_p(basenodes) = 1;
        id_prox_l = id_prox_p;
        m.fixedDFmap( basenodes, 3 ) = true;

        % create region to be marked with clones
        v_flower_p=ones(size(v_flower_p));
        v_flower_p(basenodes)=0;

        % Find all the border nodes.
        borderedges = find( m.edgecells(:,2)==0 );
        bordernodes = unique( m.edgeends( borderedges, : ) );
        bordercells = m.edgecells( borderedges, 1 );
        thickbordernodes = unique( m.tricellvxs( bordercells, : ) );

        % Set id_dist to 1 at every node on the distal edge.
        id_dist_p( bordernodes ) = 1;
        id_dist_l = id_dist_p .* id_dist_a;

        maxlatheight = 0.15;
        latrimnodes = intersect( find(m.nodes(:,3) < maxlatheight), bordernodes );
        id_lat_p(:) = 0;
        id_lat_p(latrimnodes) = 1;

        petalborderv_theta = (1:5)*0.2 - 0.5;
        petalmidv_theta = petalborderv_theta - 0.1;
        v_thetatol = 0.002;
        petalbordernodes = false( size(m.nodes,1), 1 );
        petalmidnodes = false( size(m.nodes,1), 1 );
        for i=1:length(v_theta_p)
            th = v_theta_p(i);
            bth = abs(petalborderv_theta-th);
            if any( (bth < v_thetatol) | (1-bth < v_thetatol) )
                petalbordernodes(i) = true;
            end
            mth = abs(petalmidv_theta-th);
            if any( (mth < v_thetatol) | (1-mth < v_thetatol) )
                petalmidnodes(i) = true;
            end
        end
        id_lat_p(petalbordernodes) = 1;
        id_lat_p(innerbasenodes) = 0;
        id_med_p(:) = zeros(size(id_med_p));
        id_med_p(petalmidnodes) = 1;
        id_med_p(innerbasenodes) = 0;
        id_lat_l = id_lat_p .* id_lat_a;
        id_med_l = id_med_p .* id_med_a;

        lobenodes = m.nodes(:,3) > -0.05;
        id_lobe_p(lobenodes) = 1;
        % the levels of clamped nodes (vertices) cannot change during
        % simulation
        m.morphogenclamp(lobenodes,id_lobe_i) = 1;

        id_tubenodes = m.nodes(:,3) <-0.03 & m.nodes(:,3) > - 0.18;
        id_tube_p(id_tubenodes) = 1;
        m.morphogenclamp(id_tubenodes,id_tube_i) = 1;

        id_lipnodes = m.nodes(:,3) > pd_offset-0.11 & m.nodes(:,3) < pd_offset+0.02;
        id_lip_p(id_lipnodes) = 1;
        m.morphogenclamp(id_lipnodes,id_lip_i) = 1;

        id_rimnodes = m.nodes(:,3) > pd_offset-0.07 & m.nodes(:,3) < pd_offset-0.03;
        id_rim_p(id_rimnodes) = 1;
        m.morphogenclamp(id_rimnodes,id_rim_i) = 1;

        % set up the seams ready for dissection
        %         % (adult petals are dissected and flattened - Figures 5 and 6)
        %         lobe_base_nodes = m.nodes(:,3) < -0.03 & m.nodes(:,3) > -0.05;
        %         f_seam_p(id_tube_p>0)=1;
        %         f_seam_p(id_lip_p>0)=1;
        %         f_seam_p=f_seam_p.*id_lat_p;
        %         f_seam_p(lobe_base_nodes)=1;
        %         basenodes2 = m.nodes(:,3)< -0.17 & m.nodes(:,3) > -0.2;
        %         f_seam_p(basenodes2) = 1;
        %         m.morphogenclamp(f_seam_p>0.5,f_seam_i) = 1;
        %         % use m.edgeends, m.seams, m.nodes
        %         % find nodes to be included in seams
        %         seamnodes=find(f_seam_p>0.5);
        %         % find edges joining the nodes
        %         jn=[];
        %         for i=1:length(m.edgeends)
        %             ind=intersect(seamnodes,m.edgeends(i,:));
        %             if length(ind)==2
        %                 jn(end+1)=i;
        %             end
        %         end
        %         % set seams
        %         m.seams=false(size(m.edgeends,1),1);
        %         m.seams(jn)=true;
        %         % use f_seam as a marker
        % set up the seams ready for dissection
        % (adult petals are dissected and flattened - Figures 5 and 6)
        f_seppetals_p(id_tube_p>0)=1; % all tube
        f_seppetals_p(id_lip_p>0)=1; % all lip
        f_seppetals_p=f_seppetals_p.*id_lat_p; % separate petals
        id_rimnodes = m.nodes(:,3) > pd_offset-0.01 & m.nodes(:,3) < pd_offset+0.01; % cut off lobes
        f_seplobes1_p(id_rimnodes)=1; % separate lobes from tube
        id_rimnodes = m.nodes(:,3) > pd_offset-0.060 & m.nodes(:,3) < pd_offset-0.035; % cut off lobes
        f_seplobes2_p(id_rimnodes)=1; % separate lobes from tube
        id_rimnodes = m.nodes(:,3) > pd_offset-0.085 & m.nodes(:,3) < pd_offset-0.065; % cut off lobes
        f_seplobes3_p(id_rimnodes)=1; % separate lobes from tube
        basenodes2 = m.nodes(:,3)< -0.17 & m.nodes(:,3) > -0.2;
        f_sepbase_p(basenodes2) = 1; % separate tube from base
        %m=leaf_set_seams(m,f_seam_p);
        % use f_seam as a marker

        % activate id_dich in dorsal domain
        id_dich_p=zeros(size(id_dich_p));
        id_dichnodes = (m.nodes(:,1) < -1.70/SPACERESCALE) & ~m.userdata.innerbasenodes;
        id_dich_p(id_dichnodes) = 1;
        id_dich_l=id_dich_p.*id_dich_a;

        % activate id_cyc in dorsal domain
        id_cyc_p=zeros(size(id_cyc_p));
        id_cycnodes = (m.nodes(:,1) < -0.153) & ~m.userdata.innerbasenodes;
        id_cyc_p(id_cycnodes) = 1;
        id_cyc_l=id_cyc_p.*id_cyc_a;

    else
        if realtime>=240 && realtime<250 % over this initialisation phase
            % shrink the lobes (part of the startup process that ensures
            % triangles will not get too elongated during growth
            shrinkrate=-0.01;
            kapar_p=zeros(size(kapar_l));
            kbpar_p=zeros(size(kapar_l));
            kaper_p=zeros(size(kapar_l));
            kbper_p=zeros(size(kapar_l));
            kapar_p=shrinkrate.*pro(15,id_dtl_l.*inh(0.5, id_med_l));
            kbpar_p=shrinkrate.*pro(20,id_dtl_l.*inh (0.5, id_med_l));
        end
        disp(sprintf('\n cyc=%d dich=%d div=%d cenorg=%d v_dichdistorg=%d\n',...
            id_cyc_a,id_dich_a,id_div_a,id_cenorg_a,v_dichdistorg_a));
        %Induce sectors at 340hrs
        if (340>realtime-dt) && (340<realtime+dt)
            m = leaf_makesecondlayer( m, ...  % This function adds biological cells.
                'mode', 'each', ...  % Make biological cells randomly scattered over the flower.
                'relarea', 1/16000, ...   % Each cell has area was 1/16000 of the initial area of the flower.
                'probpervx', 'V_FLOWER', ... % induce transposed cells over whole corolla
                'numcells',4500,...%number of cells (that will become clones)
                'sides', 6, ...  % Each cell is approximated as a 6-sided regular polygon.
                'colors', [0.5 0.5 0.5], ...  % Default colour is gray but
                'colorvariation',1,... % Each cell is a random colour
                'add', true );  % These cells are added to any cells existing alread
        end


        % Setup should be common to all the models
        % Start setup
        if abs(realtime - 240) <0.5*dt %At 240 hrs
            %id_prox is fixed according to s_prox levels
            id_prox_p = 2*s_prox_l;
            id_prox_l = id_prox_p .* id_prox_a;

            %expression domain of id_lip established
            id_lip_p=zeros(size(id_lip_p));
            id_lipnodes = m.nodes(:,3) > pd_offset-0.095 & m.nodes(:,3) < pd_offset+0.01;
            id_lip_p(id_lipnodes) = 1;
            id_lip_l = id_lip_p * id_lip_a;
            m.morphogenclamp(id_lipnodes,id_lip_i) = 1;

            %expression domain of id_uptube established
            id_uptubenodes = m.nodes(:,3) > pd_offset-0.085 & m.nodes(:,3) < pd_offset-0.055;
            id_uptube_p(id_uptubenodes) = 1;
            id_uptube_l = id_uptube_p * id_uptube_a;

            %expression domain of id_lpb established
            id_lpbnodes = m.nodes(:,3) > pd_offset -0.03 & m.nodes(:,3) < pd_offset+0.01;
            id_lpb_p(id_lpbnodes) = 1;
            m.morphogenclamp(id_lpbnodes,id_lpb_i) = 1;

            %expression domain of id_mlobe established
            id_mlobenodes = m.nodes(:,3) > pd_offset -0.005 & m.nodes(:,3) < pd_offset+0.03;
            id_mlobe_p(id_mlobenodes) = 1;
            m.morphogenclamp(id_mlobenodes,id_mlobe_i) = 1;

            %expression domain of id_rim established
            id_rim_p=zeros(size(id_rim_p));
            id_rimnodes = m.nodes(:,3) > pd_offset-0.055 & m.nodes(:,3) < pd_offset-0.035;
            id_rim_p(id_rimnodes) = 1;
            id_rim_l = id_rim_p * id_rim_a;
            m.morphogenclamp(id_rimnodes,id_rim_i) = 1;

            %expression domain of id_tube established
            id_tube_p=zeros(size(id_tube_p));
            id_tubenodes = m.nodes(:,3)<= pd_offset-0.055 & m.nodes(:,3) > - 0.18;
            id_tube_p(id_tubenodes) = 1;
            id_tube_l = id_tube_p * id_tube_a;
            m.morphogenclamp(id_tubenodes,id_tube_i) = 1;

            %expression domain of id_lobe established
            id_lobe_p=zeros(size(id_lobe_p));
            id_lobenodes = m.nodes(:,3) >= pd_offset -0.055;%-0.035
            id_lobe_p(id_lobenodes) = 1;
            id_lobe_l = id_lobe_p * id_lobe_a;
            m.morphogenclamp(id_lobenodes,id_lobe_i) = 1;

        end
        % s_prox is activated by id_prox
        m.mgen_production(:,s_prox_i) = 0.1 * id_prox_l;

        % s_lpb is activated by id-lpb
        m.mgen_production(:,s_lpb_i) = 0.1 * id_lpb_l.*id_med_l;

        % s_lat is activated by id_lat
        m.mgen_production(:,s_lat_i) = 0.1 * id_lat_l;

        %s_med is activated by id_med
        m.mgen_production(:,s_med_i) = 0.1 * id_med_l; %

        if abs(realtime - 245) <0.5*dt % At 245 hrs
            %id_lat is fixed according to s_lat levels
            id_lat_p = 2.5*s_lat_l;

            %id_med is fixed according to s_med levels
            id_med_p = 2.5*s_med_l;

            id_plt_p=id_tube_l.*id_lip_l;
            id_plt_l=id_plt_p.*id_plt_a;

            id_lip_p=id_lobe_l.*id_lip_l;
            id_lip_l=id_lip_p.*id_lip_a;

            m.userdata.extra_regions_ready=true;

            id_dtl_p=id_lobe_l.*inh(10,id_lip_l);
            id_dtl_l=id_dtl_p.*id_dtl_a;
            % set up the seams ready for dissection
            % (adult petals are dissected and flattened - Figures 5 and 6)
            id_rimnodes = m.nodes(:,3) > pd_offset-0.01 & m.nodes(:,3) < pd_offset+0.01; % cut off lobes
            f_seplobes1_p(id_rimnodes)=1; % separate lobes from tube
            %m=leaf_set_seams(m,f_seam_p);
            ind_mid=s_lat_p<0.18;
            f_seam2_p(ind_mid)=1; % all elements around mid
            ind_mid=s_lat_p<0.10;
            f_seam3_p(ind_mid)=1; % all elements around mid
            ind_vent_lat=s_rad_p>0.02 & s_rad_p<0.06;
            f_seam4_p(ind_vent_lat)=1; % all elements ventral side of laterals
            ind_vent_lat=s_rad_p<=0.04;
            f_seamventral_p(ind_vent_lat)=1;
            ind_dorsal_lat=s_rad_p>0.47;
            f_seamdorsal_p(ind_dorsal_lat)=1;
        end
        v_dichdistorg_p(:)=1; % visualisation
        % End setup

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%  START INDIVIDUAL MODELS %%%%%%%%%%%%%%%%%%%%%%
        
        if strcmpi(modelnumber,'Fig 4G Model 1')
                        % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            %\latex \subsection{PRN}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
            end

            m.mgen_production(:,polariser_i) =  0.1 * (id_proxorg_l + 1 -  P .* id_distorg_l);    % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED
            % note that distorg is set elsewhere) the 0.1 seems to be an error

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            %\latex \subsection{KRN}
            % GROWTH MODEL BEGINS HERE
            if realtime >= 250 && realtime<570
                % Background growth parallel to the polariser  Eqn 200

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small  Eqn 24 CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l)... .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32  CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  CHECKED
                    ;
                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250                     
                    0.0075  ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43  CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46 CHECKED
                    .* pro (1,   id_late_p .* id_dist_l )... .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  CHECKED
                    ;

                % compute the growth rates
                kapar=Kpar ; % Eqn 300
                kbpar=Kpar ;% Eqn 310
                kaper=Kper ;% Eqn 320
                kbper=Kper ;% Eqn 330
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            end
        elseif strcmpi(modelnumber,'Fig 4J Model 1') % turn off polariser gradient
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
                m.mgen_production(:,polariser_i) = 0; %0.1 * id_proxorg_l + 0.1;    % Eqn 18 and 19 production parts of  CHECKED
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
            end

            m.mgen_production(:,polariser_i) = 0; %m.mgen_production(:,polariser_i) ...
            %- 0.1 * P .* id_distorg_l;                                           % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED
            % note that distorg is set elsewhere) the 0.1 seems to be an error

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end

            %\latex \subsection{KRN (changes)}
            % GROWTH MODEL BEGINS HERE
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Background growth parallel to the polariser  Eqn 200

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small  Eqn 24 CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l)... .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32  CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  CHECKED
                    ;
                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43  CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46 CHECKED
                    .* pro (1,   id_late_p .* id_dist_l )... .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  CHECKED
                    ;

                % compute the growth rates
                kapar=Kpar ; % Eqn 300
                kbpar=Kpar ;% Eqn 310
                kaper=Kper ;% Eqn 320
                kbper=Kper ;% Eqn 330
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            end
        elseif strcmpi(modelnumber,'Fig 4K Model 1') % This was copied from Fig 4G Model 1 and Eqn 38 and 50 commented out
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
            end

            m.mgen_production(:,polariser_i) =  0.1 * (id_proxorg_l + 1 - P .* id_distorg_l);    % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED
            % note that distorg is set elsewhere) the 0.1 seems to be an error

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            %\latex \subsection{KRN (changes)}

            % GROWTH MODEL BEGINS HERE
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Background growth parallel to the polariser  Eqn 200

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small  Eqn 24 CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l)... .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32  CHECKED
                    ... .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  CHECKED
                    ;
                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43  CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46 CHECKED
                    .* pro (1,   id_late_p .* id_dist_l )... .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  CHECKED
                    ... .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  CHECKED
                    ;

                % compute the growth rates
                kapar=Kpar ; % Eqn 300
                kbpar=Kpar ;% Eqn 310
                kaper=Kper ;% Eqn 320
                kbper=Kper ;% Eqn 330
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            end
        elseif strcmpi(modelnumber,'Fig 5F Model 2')
                        % P EQUATIONS
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
            end

            m.mgen_production(:,polariser_i) =  0.1 * (id_proxorg_l + 1 - P .* id_distorg_l);    % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED
            % note that distorg is set elsewhere) the 0.1 seems to be an error

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            % End Polariser
            %\latex \subsection{GRN (changes)}

            id_div_p(:)=1;

            % End Gene Networks
            %\latex \subsection{KRN (changes)}
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Background growth parallel to the polariser  Eqn 200
                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small                                  Eqn 24 CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube      Eqn 25 CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l )... .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32  CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe       Eqn 38  CHECKED
                    ...
                    .* pro (2.4, id_early_p .* id_div_l.*id_plt_l )... %make lower tube arch over      Eqn 31  CHECKED
                    ;

                %AKapar=0.06* (id_early_p .* id_rim_l) .*  (1.2*id_div_l); % bend back petals   Eqn 36  CHECKED

                % Background growth normal to the polariser   Eqn 201
                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small                                             Eqn 43 CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe        Eqn 46 CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow            Eqn 50  CHECKED
                    ...
                    .* pro (1,   id_late_p .* id_dist_l .* pro (1.2, id_div_l))... % increase width of distal lobe   Eqn 49  CHECKED CHANGED
                    .* inh (1, id_late_p .* id_div_l .* inh(10, id_lobe_l))... .* inh (2,id_lpb_l)).* pro(1, id_plt_l))...  %narrow ventral petals    Eqn 51 CHECKED NOW REPLACE DTL BY LOBE
                    ;

                % compute the growth rates
                kapar=Kpar ...% Eqn 300
                    + 0.06* (id_early_p .* id_rim_l) .*  (1.2*id_div_l); % Eqn 301
                kbpar=Kpar ;% Eqn 310
                kaper=Kper ;% Eqn 320
                kbper=Kper ;% Eqn 330
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
            end

        elseif strcmpi(modelnumber,'Fig 6G Model 3')
            %             % P EQUATIONS
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
            end

            m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 - P .* id_distorg_l);                                           % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED
            % note that distorg is set elsewhere) the 0.1 seems to be an error

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            % End Polariser
            %\latex \subsection{GRN (changes)}

            % id_rad is activated by id_cyc and id_dich at ALL TIMES
            id_rad_p = id_cyc_l +  0.3* id_dich_l;                                           % Eqn 1 % CHECKED
            id_rad_l = id_rad_p * id_rad_a;

            % s_rad is activated by id_rad
            m.mgen_production(:,s_rad_i) = 0.1 * id_rad_l .* pro (0.5, id_tube_l);          % Eqn 14 % CHECKED

            % I suspect that it is the order within this set of equations that matters because
            % cenorg depends on div and rim in the setup secton that also happen
            % at 240
            if abs(realtime - 240) <0.5*dt %At 240 hrs
                % continue with the initial regionalisation
                % replace [0,1] values with reals for quantitative growth

                %switch on id_div
                id_div_p=inh(100, id_rad_l);                           % Eqn 5 % CHECKED
                id_div_l=id_div_p.*id_div_a;

                %id_laterals is activated by id_div
                id_lts_p(:) = id_div_l;                                                      % Eqn 6 % CHECKED
                id_lts_l=id_lts_p * id_lts_a;
            end

            if abs(realtime - 250) <0.5*dt % At time 250 hrs
                %id_cyc and id_dich are inhibited by id_div in absence of id_rad.
                %This is to ensure that in a id_rad mutant,
                %id_cyc and id_dich are inactivated. (Also see constitutive cyc
                %below)
                id_cyc_p = id_cyc_l.* inh (4, id_div_l );                                    % Eqn 7 % CHECKED
                id_cyc_l = id_cyc_p * id_cyc_a;

                id_dich_p = id_dich_l .* inh (4, id_div_l );                                 % Eqn 8 % CHECKED
                id_dich_l = id_dich_p * id_dich_a;

                % one shot setup regionalising lateral petals
                id_lts_p=5*id_lts_l.* s_rad_l;                                               % Eqn 9 % CHECKED
                id_lts_l=id_lts_p.*id_lts_a;
            end
            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                % narrow domain of div expression with id_laterals and id_rad at ~ 14 days
                id_div_p = id_div_l .* inh (5, id_lts_l);                                   % Eqn 10
                id_div_l = id_div_p.*id_div_a;
            end

            % End Gene Networks

            %\latex \subsection{KRN (changes)}
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Compute growth rates

                % Note: the factors are vectors, one element per vertex (node)
                % as a result, with each statement, different things happen in
                % different regions of the model.
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small                              Eqn 24 % CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 % CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 % CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32 % CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  % CHECKED
                    .* pro (2.4, id_early_p .* id_div_l.*id_plt_l )... %make lower tube arch over      Eqn 31 % CHECKED
                    ...
                    .* inh (1, id_rad_l .*id_lip_l .* inh(3, id_dich_l .* id_lat_l))... %prevent lip growing at edge of dorsals   Eqn 26 % CHECKED
                    .* inh (1, id_rad_l .*id_plt_l .* inh(10, id_dich_l) .* inh (20, id_cyc_l .* inh (40, id_lat_l.^2)))... %prevent palate growing at edge of dorsals   Eqn 27 % CHECKED
                    .* pro (0.3, id_cyc_l .* id_dtl_l  .* inh (0.5, id_dich_l))... %promote growth of lateral dorsal lobe         Eqn 28 % CHECKED
                    .* pro (0.45, (id_cyc_l + 0.2* id_dich_l) .* id_plt_l)... %promote medial palate growth with CYC              Eqn 29 % CHECKED
                    ;

                %AKapar=0.06* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % bend back petals   Eqn 36 % CHECKED

                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43   % CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46  % CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  % CHECKED
                    .* pro (1,   id_late_p .* id_dist_l .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  % CHECKED
                    .* inh (1, id_late_p .* id_div_l .* inh(10, id_lobe_l))... .* inh (2,id_lpb_l)).* pro(1, id_plt_l))...  %narrow ventral petals    Eqn 51  % CHECKED USED LOBE NOT DTL
                    ...
                    .* pro (0.1, id_cyc_l  .* pro(1.5,id_lip_l))... % increase width of dorsal petal    Eqn 44  % CHECKED
                    .* inh(6, id_early_p .* id_lts_l.*id_med_l )... %  keep laterals narrow initially   Eqn 45
                    .* pro (0.2, id_late_p .* id_lts_l .* id_med_l .*  id_plt_l); %promote growth of lateral width   Eqn 52   ADDD Fig 6G Model 3

                % compute the growth rates
                kapar=Kpar ...% Eqn 300
                    + 0.06* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % Eqn 301
                kbpar=Kpar ;% Eqn 310
                kaper=Kper ;% Eqn 320
                kbper=Kper ;% Eqn 330
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
            end
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        elseif strcmpi(modelnumber,'Fig 7B Model 4')
            % P EQUATIONS
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
            end

            m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 - P .* id_distorg_l);  % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED
            % note that distorg is set elsewhere) the 0.1 seems to be an error

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            % End Polariser
            %\latex \subsection{GRN (changes)}

            % id_rad is activated by id_cyc and id_dich at ALL TIMES
            id_rad_p = id_cyc_l +  0.3* id_dich_l;                                           % Eqn 1 % CHECKED
            id_rad_l = id_rad_p * id_rad_a;

            % s_rad is activated by id_rad
            m.mgen_production(:,s_rad_i) = 0.1 * id_rad_l .* pro (0.5, id_tube_l);          % Eqn 14 % CHECKED

            % I suspect that it is the order within this set of equations that matters because
            % cenorg depends on div and rim in the setup secton that also happen
            % at 240
            if abs(realtime - 240) <0.5*dt %At 240 hrs
                % continue with the initial regionalisation
                % replace [0,1] values with reals for quantitative growth

                %switch on id_div
                id_div_p=inh(100, id_rad_l);                           % Eqn 5 % CHECKED
                id_div_l=id_div_p.*id_div_a;

                %id_laterals is activated by id_div
                id_lts_p(:) = id_div_l;                                                      % Eqn 6 % CHECKED
                id_lts_l=id_lts_p * id_lts_a;
            end

            if abs(realtime - 250) <0.5*dt % At time 250 hrs
                %id_cyc and id_dich are inhibited by id_div in absence of id_rad.
                %This is to ensure that in a id_rad mutant,
                %id_cyc and id_dich are inactivated. (Also see constitutive cyc
                %below)
                id_cyc_p = id_cyc_l.* inh (4, id_div_l );                                    % Eqn 7 % CHECKED
                id_cyc_l = id_cyc_p * id_cyc_a;

                id_dich_p = id_dich_l .* inh (4, id_div_l );                                 % Eqn 8 % CHECKED
                id_dich_l = id_dich_p * id_dich_a;

                % one shot setup regionalising lateral petals
                id_lts_p=5*id_lts_l.* s_rad_l;                                               % Eqn 9 % CHECKED
                id_lts_l=id_lts_p.*id_lts_a;
            end
            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                % narrow domain of div expression with id_laterals and id_rad at ~ 14 days
                id_div_p = id_div_l .* inh (5, id_lts_l);                                   % Eqn 10
                id_div_l = id_div_p.*id_div_a;
            end

            % End Gene Networks

            %\latex \subsection{KRN (changes)}
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Compute growth rates

                % Note: the factors are vectors, one element per vertex (node)
                % as a result, with each statement, different things happen in
                % different regions of the model.
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small                              Eqn 24 % CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 % CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 % CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32 % CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  % CHECKED
                    .* pro (2.4, id_early_p .* id_div_l.*id_plt_l )... %make lower tube arch over      Eqn 31 % CHECKED
                    .* inh (1, id_rad_l .*id_lip_l .* inh(3, id_dich_l .* id_lat_l))... %prevent lip growing at edge of dorsals   Eqn 26 % CHECKED
                    .* inh (1, id_rad_l .*id_plt_l .* inh(10, id_dich_l) .* inh (20, id_cyc_l .* inh (40, id_lat_l.^2)))... %prevent palate growing at edge of dorsals   Eqn 27 % CHECKED
                    .* pro (0.3, id_cyc_l .* id_dtl_l  .* inh (0.5, id_dich_l))... %promote growth of lateral dorsal lobe         Eqn 28 % CHECKED
                    .* pro (0.45, (id_cyc_l + 0.2* id_dich_l) .* id_plt_l)... %promote medial palate growth with CYC              Eqn 29 % CHECKED
                    ;

                %AKapar=0.06* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % bend back petals   Eqn 36 % CHECKED

                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43   % CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46  % CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  % CHECKED
                    .* pro (1,   id_late_p .* id_dist_l .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  % CHECKED
                    .* inh (1, id_late_p .* id_div_l .* inh(10, id_lobe_l))... .* inh (2,id_lpb_l)).* pro(1, id_plt_l))...  %narrow ventral petals    Eqn 51  % CHECKED USED LOBE NOT DTL
                    .* pro (0.1, id_cyc_l  .* pro(1.5,id_lip_l))... % increase width of dorsal petal    Eqn 44  % CHECKED
                    .* inh(6, id_early_p .* id_lts_l.*id_med_l )... %  keep laterals narrow initially   Eqn 45
                    .* pro (0.2, id_late_p .* id_lts_l .* id_med_l .*  id_plt_l)... %promote growth of lateral width   Eqn 52   ADDD Fig 6G Model 3
                    ...
                    .* pro (3.5, id_late_p.*id_lts_l .* id_med_l .* inh(4, id_lat_l) .*pro(1,(id_lip_l + 0.3* id_plt_l)))...%  Fig 6G Model 3M1 promote lateral growth (from par)
                    ;
                % compute the growth rates
                kapar=Kpar ...% Eqn 300
                    +0.06* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % Eqn 301
                kbpar=Kpar ;% Eqn 310
                kaper=Kper ;% Eqn 320
                kbper=Kper ;% Eqn 330
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
            end
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        elseif strcmpi(modelnumber,'Fig 7I Model 5')
            % P EQUATIONS
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            m = leaf_mgen_conductivity( m, 's_cenorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_cenorg', 0.05);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
            end
            if abs(realtime - 245) <0.5*dt %At 240 hrs
                %id_cenorg is activated by id_rim, id_lat and
                % id_div in absence of id_rad
                id_cenorg_p = 0.6*id_lat_l .* id_rim_l .* id_div_l ;                                   % Eqn 4 % CHECKED
                id_cenorg_l = id_cenorg_p * id_cenorg_a;
            end

            %m.mgen_production(:,polariser_i) = m.mgen_production(:,polariser_i) - 0.1 * P .* (id_distorg_l+3*id_late_p.*id_cenorg_l);                                           % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE
            m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 - P .* (id_distorg_l+3*id_late_p.*id_cenorg_l));  % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED
            % note that distorg is set elsewhere) the 0.1 seems to be an error

            % s_cenorg is activated by id_cenorg
            m.mgen_production(:,s_cenorg_i) = 0.1 * id_cenorg_l;                             % Eqn 16 % CHECKED

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_cenorg_p = s_cenorg_l;                                                   % Eqn 11 % CHECKED
                id_cenorg_l = id_cenorg_p .* id_cenorg_a;
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            % End Polariser
            %\latex \subsection{GRN (changes)}

            % id_rad is activated by id_cyc and id_dich at ALL TIMES
            id_rad_p = id_cyc_l +  0.3* id_dich_l;                                           % Eqn 1 % CHECKED
            id_rad_l = id_rad_p * id_rad_a;

            % s_rad is activated by id_rad
            m.mgen_production(:,s_rad_i) = 0.1 * id_rad_l .* pro (0.5, id_tube_l);          % Eqn 14 % CHECKED

            % I suspect that it is the order within this set of equations that matters because
            % cenorg depends on div and rim in the setup secton that also happen
            % at 240
            if abs(realtime - 240) <0.5*dt % At time 240 hrs
                % continue with the initial regionalisation
                % replace [0,1] values with reals for quantitative growth

                %switch on id_div
                id_div_p=inh(100, id_rad_l);                           % Eqn 5 % CHECKED
                id_div_l=id_div_p.*id_div_a;

                %id_laterals is activated by id_div
                id_lts_p(:) = id_div_l;                                                      % Eqn 6 % CHECKED
                id_lts_l=id_lts_p * id_lts_a;
            end

            if abs(realtime - 250) <0.5*dt % At time 250 hrs
                %id_cyc and id_dich are inhibited by id_div in absence of id_rad.
                %This is to ensure that in a id_rad mutant,
                %id_cyc and id_dich are inactivated. (Also see constitutive cyc
                %below)
                id_cyc_p = id_cyc_l.* inh (4, id_div_l );                                    % Eqn 7 % CHECKED
                id_cyc_l = id_cyc_p * id_cyc_a;

                id_dich_p = id_dich_l .* inh (4, id_div_l );                                 % Eqn 8 % CHECKED
                id_dich_l = id_dich_p * id_dich_a;

                % one shot setup regionalising lateral petals
                id_lts_p=5*id_lts_l.* s_rad_l;                                               % Eqn 9 % CHECKED
                id_lts_l=id_lts_p.*id_lts_a;
            end
            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                % narrow domain of div expression with id_laterals and id_rad at ~ 14 days
                id_div_p = id_div_l .* inh (5, id_lts_l);                                   % Eqn 10
                id_div_l = id_div_p.*id_div_a;
            end

            % End Gene Networks

            %\latex \subsection{KRN (changes)}
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Compute growth rates

                % Note: the factors are vectors, one element per vertex (node)
                % as a result, with each statement, different things happen in
                % different regions of the model.
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small                              Eqn 24 % CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 % CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 % CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32 % CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  % CHECKED
                    .* pro (2.4, id_early_p .* id_div_l.*id_plt_l )... %make lower tube arch over      Eqn 31 % CHECKED
                    .* inh (1, id_rad_l .*id_lip_l .* inh(3, id_dich_l .* id_lat_l))... %prevent lip growing at edge of dorsals   Eqn 26 % CHECKED
                    .* inh (1, id_rad_l .*id_plt_l .* inh(10, id_dich_l) .* inh (20, id_cyc_l .* inh (40, id_lat_l.^2)))... %prevent palate growing at edge of dorsals   Eqn 27 % CHECKED
                    .* pro (0.3, id_cyc_l .* id_dtl_l  .* inh (0.5, id_dich_l))... %promote growth of lateral dorsal lobe         Eqn 28 % CHECKED
                    .* pro (0.45, (id_cyc_l + 0.2* id_dich_l) .* id_plt_l)... %promote medial palate growth with CYC              Eqn 29 % CHECKED
                    ...
                    .* pro (2.2, id_late_p .* id_lts_l .* id_med_l .* inh (0.5, id_lpb_l).* inh(4, id_lat_l) .*(id_lip_l + 0.3* id_plt_l));%  promote lateral growth   Eqn 42 % CHECKED


                %AKapar=0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % bend back petals   Eqn 36 % CHECKED

                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43   % CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46  % CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  % CHECKED
                    .* pro (1,   id_late_p .* id_dist_l .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  % CHECKED
                    .* inh (1, id_late_p .* id_div_l .* inh(10, id_lobe_l))... .* inh (2,id_lpb_l)).* pro(1, id_plt_l))...  %narrow ventral petals    Eqn 51  % CHECKED USED LOBE NOT DTL
                    .* pro (0.1, id_cyc_l  .* pro(1.5,id_lip_l))... % increase width of dorsal petal    Eqn 44  % CHECKED
                    .* inh(6, id_early_p .* id_lts_l.*id_med_l )... %  keep laterals narrow initially   Eqn 45
                    .* pro (0.2, id_late_p .* id_lts_l .* id_med_l .*  id_plt_l); %promote growth of lateral width   Eqn 52   ADDD Fig 6G Model 3

                % compute the growth rates
                kapar=Kpar ...% Eqn 300
                    +0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % Eqn 301
                kbpar=Kpar ;% Eqn 310
                kaper=Kper ;% Eqn 320
                kbper=Kper ;% Eqn 330
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
            end
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        elseif strcmpi(modelnumber,'Fig 8C Model 6') %
            % P EQUATIONS
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            m = leaf_mgen_conductivity( m, 's_cenorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_cenorg', 0.05);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
%                 id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l)...                       % CHECKED
%                     + 0.1*(v_dichdistorg_p.*id_dich_l) .* id_dist_l .* id_cyc_l;           % Eqn 3 (used in production equation)
%                 id_distorg_l = id_distorg_p * id_distorg_a;
%                 m.userdata.all_regions_ready=true;
%                 v_dichdistorg_p=v_dichdistorg_p.*id_dich_l.* id_dist_l .* id_cyc_l;
            end
            
            if abs(realtime - 245) <0.5*dt %At 240 hrs
                %id_cenorg is activated by id_rim, id_lat and
                % id_div in absence of id_rad
                id_cenorg_p = 0.6*id_lat_l .* id_rim_l .* id_div_l ;                                   % Eqn 4 % CHECKED
                id_cenorg_l = id_cenorg_p * id_cenorg_a;
            end

            m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 - P .* (id_distorg_l+3*id_late_p.*id_cenorg_l));  % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED

            % s_cenorg is activated by id_cenorg
            m.mgen_production(:,s_cenorg_i) = 0.1 * id_cenorg_l;                             % Eqn 16 % CHECKED

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_cenorg_p = s_cenorg_l;                                                   % Eqn 11 % CHECKED
                id_cenorg_l = id_cenorg_p .* id_cenorg_a;
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            % End Polariser
            %\latex \subsection{GRN (changes)}

            % id_rad is activated by id_cyc and id_dich at ALL TIMES
            id_rad_p = id_cyc_l +  0.3* id_dich_l;                                           % Eqn 1 % CHECKED
            id_rad_l = id_rad_p * id_rad_a;

            % s_rad is activated by id_rad
            m.mgen_production(:,s_rad_i) = 0.1 * id_rad_l .* pro (0.5, id_tube_l);          % Eqn 14 % CHECKED

            % I suspect that it is the order within this set of equations that matters because
            % cenorg depends on div and rim in the setup secton that also happen
            % at 240
            if abs(realtime - 240) <0.5*dt %At 240 hrs
                % continue with the initial regionalisation
                % replace [0,1] values with reals for quantitative growth

                %switch on id_div
                id_div_p=inh(100, id_rad_l);                           % Eqn 5 % CHECKED
                id_div_l=id_div_p.*id_div_a;

                %id_laterals is activated by id_div
                id_lts_p(:) = id_div_l;                                                      % Eqn 6 % CHECKED
                id_lts_l=id_lts_p * id_lts_a;
            end

            if abs(realtime - 250) <0.5*dt % At time 250 hrs
                %id_cyc and id_dich are inhibited by id_div in absence of id_rad.
                %This is to ensure that in a id_rad mutant,
                %id_cyc and id_dich are inactivated. (Also see constitutive cyc
                %below)
                id_cyc_p = id_cyc_l.* inh (4, id_div_l );                                    % Eqn 7 % CHECKED
                id_cyc_l = id_cyc_p * id_cyc_a;

                id_dich_p = id_dich_l .* inh (4, id_div_l );                                 % Eqn 8 % CHECKED
                id_dich_l = id_dich_p * id_dich_a;

                % one shot setup regionalising lateral petals
                id_lts_p=5*id_lts_l.* s_rad_l;                                               % Eqn 9 % CHECKED
                id_lts_l=id_lts_p.*id_lts_a;
            end
            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                % narrow domain of div expression with id_laterals and id_rad at ~ 14 days
                id_div_p = id_div_l .* inh (5, id_lts_l);                                   % Eqn 10
                id_div_l = id_div_p.*id_div_a;
            end

            % End Gene Networks

            %\latex \subsection{KRN (changes)}
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Compute growth rates

                % Note: the factors are vectors, one element per vertex (node)
                % as a result, with each statement, different things happen in
                % different regions of the model.
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small                              Eqn 24 % CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 % CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 % CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32 % CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  % CHECKED
                    .* pro (2.4, id_early_p .* id_div_l.*id_plt_l )... %make lower tube arch over      Eqn 31 % CHECKED
                    .* inh (1, id_rad_l .*id_lip_l .* inh(3, id_dich_l .* id_lat_l))... %prevent lip growing at edge of dorsals   Eqn 26 % CHECKED
                    .* inh (1, id_rad_l .*id_plt_l .* inh(10, id_dich_l) .* inh (20, id_cyc_l .* inh (40, id_lat_l.^2)))... %prevent palate growing at edge of dorsals   Eqn 27 % CHECKED
                    .* pro (0.3, id_cyc_l .* id_dtl_l  .* inh (0.5, id_dich_l))... %promote growth of lateral dorsal lobe         Eqn 28 % CHECKED
                    .* pro (0.45, (id_cyc_l + 0.2* id_dich_l) .* id_plt_l)... %promote medial palate growth with CYC              Eqn 29 % CHECKED
                    .* pro (2.2, id_late_p .* id_lts_l .* id_med_l .* inh (0.5, id_lpb_l).* inh(4, id_lat_l) .*(id_lip_l + 0.3* id_plt_l))...%  promote lateral growth   Eqn 42 % CHECKED
                    ... %%%%%%% FINE TUNING %%%%%% better formed palate
                    .* inh (10,  id_late_p .* id_div_l .*id_cenorg_l.* inh(2, id_lpb_l).* pro (10, id_plt_l .* id_med_l))...% prevent lips protruding   Eqn 39
                    .* pro (0.2, id_late_p .* id_div_l .* id_plt_l)... %promote growth of palate   Eqn 40
                    .* inh (0.7, id_late_p .* id_lts_l .* id_lat_l .* (id_lip_l + id_plt_l)); %inhibit growth at edge of laterals   Eqn 41



%                 DKapar=1 ... %%%%%%% FINE TUNING %%%%%%
%                     .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
%                     .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
%                     .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35

                %AKapar=0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % bend back petals   Eqn 36 % CHECKED
                 
                %%%%%%% FINE TUNING %%%%%%
                %DKbpar=pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % bend dorsal lip forward   Eqn 37  % CHECKED 

                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43   % CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46  % CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  % CHECKED
                    .* pro (1,   id_late_p .* id_dist_l .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  % CHECKED
                    .* inh (1.3, id_late_p .* id_div_l .* inh(2.5, id_lobe_l.* inh (2,id_lpb_l)).* pro(1, id_plt_l))...  %narrow ventral petals    Eqn 51 %%%%%%% FINE TUNING %%%%%%
                    .* pro (0.1, id_cyc_l  .* pro(1.5,id_lip_l))... % increase width of dorsal petal    Eqn 44  % CHECKED
                    .* inh(6, id_early_p .* id_lts_l.*id_med_l )... %  keep laterals narrow initially   Eqn 45
                    .* pro (0.2, id_late_p .* id_lts_l .* id_med_l .*  id_plt_l); %promote growth of lateral width   Eqn 52   ADDD Fig 6G Model 3

                %%%%%%% FINE TUNING %%%%%%
%                 DKaper = pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
%                 DKbper = inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48


                % compute the growth rates
                kapar=Kpar ...% Eqn 300
                    .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
                    .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
                    .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35
                    +0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % Eqn 301
                kbpar=Kpar ... % Eqn 310
                    .*pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % Eqn 37
                kaper=Kper ... % Eqn 320
                    .* pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
                kbper=Kper ... % Eqn 330
                    .*inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48 
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
            end
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        elseif strcmpi(modelnumber,'Fig 9B Model 7') || strcmpi(modelnumber,'Fig 9B Model 7M2') || strcmpi(modelnumber,'Fig 9B Model 7M3') 
            % P EQUATIONS
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            m = leaf_mgen_conductivity( m, 's_cenorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_cenorg', 0.05);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
%                 id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
%                 id_distorg_l = id_distorg_p * id_distorg_a;
%                 m.userdata.all_regions_ready=true;
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l)+ 0.1*id_dich_l .* id_dist_l .* id_cyc_l;           % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
                v_dichdistorg_p=v_dichdistorg_p.*id_dich_l.* id_dist_l .* id_cyc_l;
            end
            
            if abs(realtime - 245) <0.5*dt %At 240 hrs
                %id_cenorg is activated by id_rim, id_lat and
                % id_div in absence of id_rad
                id_cenorg_p = 0.6*id_lat_l .* id_rim_l .* id_div_l ;                                   % Eqn 4 % CHECKED
                id_cenorg_l = id_cenorg_p * id_cenorg_a;
            end

            m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 - P .* (id_distorg_l+3*id_late_p.*id_cenorg_l)); % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE
            %m.mgen_production(:,polariser_i) = m.mgen_production(:,polariser_i) - 0.1 * P .* (id_distorg_l+3*id_late_p.*id_cenorg_l);  % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED

            % s_cenorg is activated by id_cenorg
            m.mgen_production(:,s_cenorg_i) = 0.1 * id_cenorg_l;                             % Eqn 16 % CHECKED

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_cenorg_p = s_cenorg_l;                                                   % Eqn 11 % CHECKED
                id_cenorg_l = id_cenorg_p .* id_cenorg_a;
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            % End Polariser
            %\latex \subsection{GRN (changes)}

            % id_rad is activated by id_cyc and id_dich at ALL TIMES
            id_rad_p = id_cyc_l +  0.3* id_dich_l;                                           % Eqn 1 % CHECKED
            id_rad_l = id_rad_p * id_rad_a;

            % s_rad is activated by id_rad
            m.mgen_production(:,s_rad_i) = 0.1 * id_rad_l .* pro (0.5, id_tube_l);          % Eqn 14 % CHECKED

            % I suspect that it is the order within this set of equations that matters because
            % cenorg depends on div and rim in the setup secton that also happen
            % at 240
            if abs(realtime - 240) <0.5*dt %At 240 hrs
                % continue with the initial regionalisation
                % replace [0,1] values with reals for quantitative growth

                %switch on id_div
                id_div_p=inh(100, id_rad_l);                           % Eqn 5 % CHECKED
                id_div_l=id_div_p.*id_div_a;

                %id_laterals is activated by id_div
                id_lts_p(:) = id_div_l;                                                      % Eqn 6 % CHECKED
                id_lts_l=id_lts_p * id_lts_a;
            end

            if abs(realtime - 250) <0.5*dt % At time 250 hrs
                %id_cyc and id_dich are inhibited by id_div in absence of id_rad.
                %This is to ensure that in a id_rad mutant,
                %id_cyc and id_dich are inactivated. (Also see constitutive cyc
                %below)
                id_cyc_p = id_cyc_l.* inh (4, id_div_l );                                    % Eqn 7 % CHECKED
                id_cyc_l = id_cyc_p * id_cyc_a;

                id_dich_p = id_dich_l .* inh (4, id_div_l );                                 % Eqn 8 % CHECKED
                id_dich_l = id_dich_p * id_dich_a;

                % one shot setup regionalising lateral petals
                id_lts_p=5*id_lts_l.* s_rad_l;                                               % Eqn 9 % CHECKED
                id_lts_l=id_lts_p.*id_lts_a;
            end
            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                % narrow domain of div expression with id_laterals and id_rad at ~ 14 days
                id_div_p = id_div_l .* inh (5, id_lts_l);                                   % Eqn 10
                id_div_l = id_div_p.*id_div_a;
            end

            % End Gene Networks

            %\latex \subsection{KRN (changes)}
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Compute growth rates

                % Note: the factors are vectors, one element per vertex (node)
                % as a result, with each statement, different things happen in
                % different regions of the model.
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small                              Eqn 24 % CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 % CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 % CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32 % CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  % CHECKED
                    .* pro (2.4, id_early_p .* id_div_l.*id_plt_l )... %make lower tube arch over      Eqn 31 % CHECKED
                    .* inh (1, id_rad_l .*id_lip_l .* inh(3, id_dich_l .* id_lat_l))... %prevent lip growing at edge of dorsals   Eqn 26 % CHECKED
                    .* inh (1, id_rad_l .*id_plt_l .* inh(10, id_dich_l) .* inh (20, id_cyc_l .* inh (40, id_lat_l.^2)))... %prevent palate growing at edge of dorsals   Eqn 27 % CHECKED
                    .* pro (0.3, id_cyc_l .* id_dtl_l  .* inh (0.5, id_dich_l))... %promote growth of lateral dorsal lobe         Eqn 28 % CHECKED
                    .* pro (0.45, (id_cyc_l + 0.2* id_dich_l) .* id_plt_l)... %promote medial palate growth with CYC              Eqn 29 % CHECKED
                    .* pro (2.2, id_late_p .* id_lts_l .* id_med_l .* inh (0.5, id_lpb_l).* inh(4, id_lat_l) .*(id_lip_l + 0.3* id_plt_l))...%  promote lateral growth   Eqn 42 % CHECKED
                    ... %%%%%%% FINE TUNING %%%%%% better formed palate
                    .* inh (10,  id_late_p .* id_div_l .*id_cenorg_l.* inh(2, id_lpb_l).* pro (10, id_plt_l .* id_med_l))...% prevent lips protruding   Eqn 39
                    .* pro (0.2, id_late_p .* id_div_l .* id_plt_l)... %promote growth of palate   Eqn 40
                    .* inh (0.7, id_late_p .* id_lts_l .* id_lat_l .* (id_lip_l + id_plt_l)); %inhibit growth at edge of laterals   Eqn 41



%                 DKapar=1 ... %%%%%%% FINE TUNING %%%%%%
%                     .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
%                     .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
%                     .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35

                %AKapar=0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % bend back petals   Eqn 36 % CHECKED
                 
                %%%%%%% FINE TUNING %%%%%%
%                 DKbpar=pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % bend dorsal lip forward   Eqn 37  % CHECKED 

                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43   % CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46  % CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  % CHECKED
                    .* pro (1,   id_late_p .* id_dist_l .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  % CHECKED
                    .* inh (1.3, id_late_p .* id_div_l .* inh(2.5, id_lobe_l.* inh (2,id_lpb_l)).* pro(1, id_plt_l))...  %narrow ventral petals    Eqn 51 %%%%%%% FINE TUNING %%%%%%
                    .* pro (0.1, id_cyc_l  .* pro(1.5,id_lip_l))... % increase width of dorsal petal    Eqn 44  % CHECKED
                    .* inh(6, id_early_p .* id_lts_l.*id_med_l )... %  keep laterals narrow initially   Eqn 45
                    .* pro (0.2, id_late_p .* id_lts_l .* id_med_l .*  id_plt_l); %promote growth of lateral width   Eqn 52   ADDD Fig 6G Model 3

                %%%%%%% FINE TUNING %%%%%%
%                 DKaper = pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
%                 DKbper = inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48


                % compute the growth rates
                kapar=Kpar ...% Eqn 300
                    .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
                    .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
                    .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35
                    +0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % Eqn 301
                kbpar=Kpar ... % Eqn 310
                    .*pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % Eqn 37
                kaper=Kper ... % Eqn 320
                    .* pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
                kbper=Kper ... % Eqn 330
                    .*inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48 
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
            end
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        elseif strcmpi(modelnumber,'Fig 9B Model 7M1') % need to change cenorg to +organiser 
            % P EQUATIONS
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            m = leaf_mgen_conductivity( m, 's_cenorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_cenorg', 0.05);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
                %m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 + 3*id_late_p.*id_cenorg_l);    % Eqn 18 and 19 production parts of  CHECKED
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
%                 id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
%                 id_distorg_l = id_distorg_p * id_distorg_a;
%                 m.userdata.all_regions_ready=true;
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l)+ 0.1*(id_dich_l) .* id_dist_l .* id_cyc_l;           % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
                v_dichdistorg_p=v_dichdistorg_p.*id_dich_l.* id_dist_l .* id_cyc_l;
            end
            
            if abs(realtime - 245) <0.5*dt %At 240 hrs
                %id_cenorg is activated by id_rim, id_lat and
                % id_div in absence of id_rad
                id_cenorg_p = 0.6*id_lat_l .* id_rim_l .* id_div_l ;                                   % Eqn 4 % CHECKED
                id_cenorg_l = id_cenorg_p * id_cenorg_a;
            end

            m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 + 3*id_late_p.*id_cenorg_l - P .* (id_distorg_l)); % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED

            % s_cenorg is activated by id_cenorg
            m.mgen_production(:,s_cenorg_i) = 0.1 * id_cenorg_l;                             % Eqn 16 % CHECKED

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_cenorg_p = s_cenorg_l;                                                   % Eqn 11 % CHECKED
                id_cenorg_l = id_cenorg_p .* id_cenorg_a;
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            % End Polariser
            %\latex \subsection{GRN (changes)}

            % id_rad is activated by id_cyc and id_dich at ALL TIMES
            id_rad_p = id_cyc_l +  0.3* id_dich_l;                                           % Eqn 1 % CHECKED
            id_rad_l = id_rad_p * id_rad_a;

            % s_rad is activated by id_rad
            m.mgen_production(:,s_rad_i) = 0.1 * id_rad_l .* pro (0.5, id_tube_l);          % Eqn 14 % CHECKED

            % I suspect that it is the order within this set of equations that matters because
            % cenorg depends on div and rim in the setup secton that also happen
            % at 240
            if abs(realtime - 240) <0.5*dt %At 240 hrs
                % continue with the initial regionalisation
                % replace [0,1] values with reals for quantitative growth

                %switch on id_div
                id_div_p=inh(100, id_rad_l);                           % Eqn 5 % CHECKED
                id_div_l=id_div_p.*id_div_a;

                %id_laterals is activated by id_div
                id_lts_p(:) = id_div_l;                                                      % Eqn 6 % CHECKED
                id_lts_l=id_lts_p * id_lts_a;
            end

            if abs(realtime - 250) <0.5*dt % At time 250 hrs
                %id_cyc and id_dich are inhibited by id_div in absence of id_rad.
                %This is to ensure that in a id_rad mutant,
                %id_cyc and id_dich are inactivated. (Also see constitutive cyc
                %below)
                id_cyc_p = id_cyc_l.* inh (4, id_div_l );                                    % Eqn 7 % CHECKED
                id_cyc_l = id_cyc_p * id_cyc_a;

                id_dich_p = id_dich_l .* inh (4, id_div_l );                                 % Eqn 8 % CHECKED
                id_dich_l = id_dich_p * id_dich_a;

                % one shot setup regionalising lateral petals
                id_lts_p=5*id_lts_l.* s_rad_l;                                               % Eqn 9 % CHECKED
                id_lts_l=id_lts_p.*id_lts_a;
            end
            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                % narrow domain of div expression with id_laterals and id_rad at ~ 14 days
                id_div_p = id_div_l .* inh (5, id_lts_l);                                   % Eqn 10
                id_div_l = id_div_p.*id_div_a;
            end

            % End Gene Networks

            %\latex \subsection{KRN (changes)}
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Compute growth rates

                % Note: the factors are vectors, one element per vertex (node)
                % as a result, with each statement, different things happen in
                % different regions of the model.
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small                              Eqn 24 % CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 % CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 % CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32 % CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  % CHECKED
                    .* pro (2.4, id_early_p .* id_div_l.*id_plt_l )... %make lower tube arch over      Eqn 31 % CHECKED
                    .* inh (1, id_rad_l .*id_lip_l .* inh(3, id_dich_l .* id_lat_l))... %prevent lip growing at edge of dorsals   Eqn 26 % CHECKED
                    .* inh (1, id_rad_l .*id_plt_l .* inh(10, id_dich_l) .* inh (20, id_cyc_l .* inh (40, id_lat_l.^2)))... %prevent palate growing at edge of dorsals   Eqn 27 % CHECKED
                    .* pro (0.3, id_cyc_l .* id_dtl_l  .* inh (0.5, id_dich_l))... %promote growth of lateral dorsal lobe         Eqn 28 % CHECKED
                    .* pro (0.45, (id_cyc_l + 0.2* id_dich_l) .* id_plt_l)... %promote medial palate growth with CYC              Eqn 29 % CHECKED
                    .* pro (2.2, id_late_p .* id_lts_l .* id_med_l .* inh (0.5, id_lpb_l).* inh(4, id_lat_l) .*(id_lip_l + 0.3* id_plt_l))...%  promote lateral growth   Eqn 42 % CHECKED
                    ... %%%%%%% FINE TUNING %%%%%% better formed palate
                    .* inh (10,  id_late_p .* id_div_l .*id_cenorg_l.* inh(2, id_lpb_l).* pro (10, id_plt_l .* id_med_l))...% prevent lips protruding   Eqn 39
                    .* pro (0.2, id_late_p .* id_div_l .* id_plt_l)... %promote growth of palate   Eqn 40
                    .* inh (0.7, id_late_p .* id_lts_l .* id_lat_l .* (id_lip_l + id_plt_l)); %inhibit growth at edge of laterals   Eqn 41



%                 DKapar=1 ... %%%%%%% FINE TUNING %%%%%%
%                     .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
%                     .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
%                     .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35

                %AKapar=0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % bend back petals   Eqn 36 % CHECKED
                 
                %%%%%%% FINE TUNING %%%%%%
%                 DKbpar=pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % bend dorsal lip forward   Eqn 37  % CHECKED 

                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43   % CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46  % CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  % CHECKED
                    .* pro (1,   id_late_p .* id_dist_l .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  % CHECKED
                    .* inh (1.3, id_late_p .* id_div_l .* inh(2.5, id_lobe_l.* inh (2,id_lpb_l)).* pro(1, id_plt_l))...  %narrow ventral petals    Eqn 51 %%%%%%% FINE TUNING %%%%%%
                    .* pro (0.1, id_cyc_l  .* pro(1.5,id_lip_l))... % increase width of dorsal petal    Eqn 44  % CHECKED
                    .* inh(6, id_early_p .* id_lts_l.*id_med_l )... %  keep laterals narrow initially   Eqn 45
                    .* pro (0.2, id_late_p .* id_lts_l .* id_med_l .*  id_plt_l); %promote growth of lateral width   Eqn 52   ADDD Fig 6G Model 3

                %%%%%%% FINE TUNING %%%%%%
%                 DKaper = pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
%                 DKbper = inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48


                % compute the growth rates
                kapar=Kpar ...% Eqn 300
                    .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
                    .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
                    .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35
                    +0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % Eqn 301
                kbpar=Kpar ... % Eqn 310
                    .*pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % Eqn 37
                kaper=Kper ... % Eqn 320
                    .* pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
                kbper=Kper ... % Eqn 330
                    .*inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48 
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
            end
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        elseif strcmpi(modelnumber,'Fig 9JK Model 8') %|| strcmpi(modelnumber,'Fig 9B Model 7M2') || strcmpi(modelnumber,'Fig 9B Model 7M3') 
            % P EQUATIONS
            % START POLARISER section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

            m = leaf_mgen_conductivity( m, 's_cenorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_cenorg', 0.05);  % it will not decay everywhere

            %\latex \subsection{PRN (changes)}
            % POLARISER PRODUCTION
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2  CHECKED
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % POLARISER DECAY
            % switch on distorg with id_dist in the absence of id_lat
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
%                 id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);%  CHECKED % Eqn 3 (used in production equation)
%                 id_distorg_l = id_distorg_p * id_distorg_a;
%                 m.userdata.all_regions_ready=true;
                id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l)+ 0.1*id_dich_l .* id_dist_l .* id_cyc_l;           % Eqn 3 (used in production equation)
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
                v_dichdistorg_p=v_dichdistorg_p.*id_dich_l.* id_dist_l .* id_cyc_l;
            end
            
            if abs(realtime - 245) <0.5*dt %At 240 hrs
                %id_cenorg is activated by id_rim, id_lat and
                % id_div in absence of id_rad
                %id_cenorg_p = 0.6*id_lat_l .* id_rim_l .* id_div_l ;                                   % Eqn 4 % CHECKED
                id_cenorg_p = 1*id_lat_l .* id_rim_l .* (0.03 * ones(size(id_cenorg_p))+0.57*id_div_l) ;   % MODIFIED        % Eqn 4 % CHECKED was 0.9*-.6
                %id_cenorg_p = 0.6*id_lat_l .* id_rim_l .* (0.05 * ones(size(id_cenorg_p))+0.9*id_div_l) ;   % MODIFIED        % Eqn 4 % CHECKED
                id_cenorg_l = id_cenorg_p * id_cenorg_a;
            end

            m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 - P .* (id_distorg_l+3*id_late_p.*id_cenorg_l)); % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE
            %m.mgen_production(:,polariser_i) = m.mgen_production(:,polariser_i) - 0.1 * P .* (id_distorg_l+3*id_late_p.*id_cenorg_l);  % Eqn 19 decay part of WAS S_DISTORG BY MISTAKE

            % LATER MODULATION OF DISTORG AND DIST
            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17  CHECKED

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but  CHECKED

            % s_cenorg is activated by id_cenorg
            m.mgen_production(:,s_cenorg_i) = 0.1 * id_cenorg_l;                             % Eqn 16 % CHECKED

            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_cenorg_p = s_cenorg_l;                                                   % Eqn 11 % CHECKED
                id_cenorg_l = id_cenorg_p .* id_cenorg_a;
                id_distorg_p = s_distorg_l;                                                 % Eqn 12  CHECKED
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13  CHECKED (NOT NEEDED IN THIS MODEL)
                id_dist_l = id_dist_p .* id_dist_a;
            end
            % End Polariser
            %\latex \subsection{GRN (changes)}

            % id_rad is activated by id_cyc and id_dich at ALL TIMES
            id_rad_p = id_cyc_l +  0.3* id_dich_l;                                           % Eqn 1 % CHECKED
            id_rad_l = id_rad_p * id_rad_a;

            % s_rad is activated by id_rad
            m.mgen_production(:,s_rad_i) = 0.1 * id_rad_l .* pro (0.5, id_tube_l);          % Eqn 14 % CHECKED

            % I suspect that it is the order within this set of equations that matters because
            % cenorg depends on div and rim in the setup secton that also happen
            % at 240
            if abs(realtime - 240) <0.5*dt %At 240 hrs
                % continue with the initial regionalisation
                % replace [0,1] values with reals for quantitative growth

                %switch on id_div
                id_div_p=inh(100, id_rad_l);                           % Eqn 5 % CHECKED
                id_div_l=id_div_p.*id_div_a;

                %id_laterals is activated by id_div
                id_lts_p(:) = id_div_l;                                                      % Eqn 6 % CHECKED
                id_lts_l=id_lts_p * id_lts_a;
            end

            if abs(realtime - 250) <0.5*dt % At time 250 hrs
                %id_cyc and id_dich are inhibited by id_div in absence of id_rad.
                %This is to ensure that in a id_rad mutant,
                %id_cyc and id_dich are inactivated. (Also see constitutive cyc
                %below)
                id_cyc_p = id_cyc_l.* inh (4, id_div_l );                                    % Eqn 7 % CHECKED
                id_cyc_l = id_cyc_p * id_cyc_a;

                id_dich_p = id_dich_l .* inh (4, id_div_l );                                 % Eqn 8 % CHECKED
                id_dich_l = id_dich_p * id_dich_a;

                % one shot setup regionalising lateral petals
                id_lts_p=5*id_lts_l.* s_rad_l;                                               % Eqn 9 % CHECKED
                id_lts_l=id_lts_p.*id_lts_a;
            end
            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                % narrow domain of div expression with id_laterals and id_rad at ~ 14 days
                id_div_p = id_div_l .* inh (5, id_lts_l);                                   % Eqn 10
                id_div_l = id_div_p.*id_div_a;
            end

            % End Gene Networks

            %\latex \subsection{KRN (changes)}
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Compute growth rates

                % Note: the factors are vectors, one element per vertex (node)
                % as a result, with each statement, different things happen in
                % different regions of the model.
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small                              Eqn 24 % CHECKED
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25 % CHECKED
                    .* pro (1.4, id_early_p .* id_lip_l .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30 % CHECKED
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32 % CHECKED
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38  % CHECKED
                    .* pro (2.4, id_early_p .* id_div_l.*id_plt_l )... %make lower tube arch over      Eqn 31 % CHECKED
                    .* inh (1, id_rad_l .*id_lip_l .* inh(3, id_dich_l .* id_lat_l))... %prevent lip growing at edge of dorsals   Eqn 26 % CHECKED
                    .* inh (1, id_rad_l .*id_plt_l .* inh(10, id_dich_l) .* inh (20, id_cyc_l .* inh (40, id_lat_l.^2)))... %prevent palate growing at edge of dorsals   Eqn 27 % CHECKED
                    .* pro (0.3, id_cyc_l .* id_dtl_l  .* inh (0.5, id_dich_l))... %promote growth of lateral dorsal lobe         Eqn 28 % CHECKED
                    .* pro (0.45, (id_cyc_l + 0.2* id_dich_l) .* id_plt_l)... %promote medial palate growth with CYC              Eqn 29 % CHECKED
                    .* pro (2.2, id_late_p .* id_lts_l .* id_med_l .* inh (0.5, id_lpb_l).* inh(4, id_lat_l) .*(id_lip_l + 0.3* id_plt_l))...%  promote lateral growth   Eqn 42 % CHECKED
                    ... %%%%%%% FINE TUNING %%%%%% better formed palate
                    .* inh (10,  id_late_p .* id_div_l .*id_cenorg_l.* inh(2, id_lpb_l).* pro (10, id_plt_l .* id_med_l))...% prevent lips protruding   Eqn 39
                    .* pro (0.2, id_late_p .* id_div_l .* id_plt_l)... %promote growth of palate   Eqn 40
                    .* inh (0.7, id_late_p .* id_lts_l .* id_lat_l .* (id_lip_l + id_plt_l)); %inhibit growth at edge of laterals   Eqn 41



%                 DKapar=1 ... %%%%%%% FINE TUNING %%%%%%
%                     .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
%                     .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
%                     .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35

                %AKapar=0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % bend back petals   Eqn 36 % CHECKED
                 
                %%%%%%% FINE TUNING %%%%%%
%                 DKbpar=pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % bend dorsal lip forward   Eqn 37  % CHECKED 

                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43   % CHECKED
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe    Eqn 46  % CHECKED
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50  % CHECKED
                    .* pro (1,   id_late_p .* id_dist_l .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49  % CHECKED
                    .* inh (1.3, id_late_p .* id_div_l .* inh(2.5, id_lobe_l.* inh (2,id_lpb_l)).* pro(1, id_plt_l))...  %narrow ventral petals    Eqn 51 %%%%%%% FINE TUNING %%%%%%
                    .* pro (0.1, id_cyc_l  .* pro(1.5,id_lip_l))... % increase width of dorsal petal    Eqn 44  % CHECKED
                    .* inh(6, id_early_p .* id_lts_l.*id_med_l )... %  keep laterals narrow initially   Eqn 45
                    .* pro (0.2, id_late_p .* id_lts_l .* id_med_l .*  id_plt_l); %promote growth of lateral width   Eqn 52   ADDD Fig 6G Model 3

                %%%%%%% FINE TUNING %%%%%%
%                 DKaper = pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
%                 DKbper = inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48


                % compute the growth rates
                kapar=Kpar ...% Eqn 300
                    .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
                    .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
                    .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35
                    +0.05* id_early_p .* id_rim_l .* ( 0.7*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_dich_l)+0.5*ones(size(id_cenorg_l)));% NEW  % Eqn 301
                    %+0.05* id_early_p .* id_rim_l .* (0.85*( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l))+0.5*ones(size(id_cenorg_l)));% NEW  % Eqn 301
                    %+0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % Eqn 301
                kbpar=Kpar ... % Eqn 310
                    .*pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % Eqn 37
                kaper=Kper ... % Eqn 320
                    .* pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
                kbper=Kper ... % Eqn 330
                    .*inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48 
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
            end
        elseif strcmpi(modelnumber,'WILD') % The WILD model retains the mutantnumber options needed for Minlong paper
            % P polariser equations
            % Start Polariser section (it is slightly mixed with gene networks)
            m = leaf_mgen_conductivity( m, 's_distorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_distorg', 0.05);  % it will not decay everywhere
            m = leaf_mgen_conductivity( m, 's_cenorg', 0.002); %was 0.1 distorg_diff);% diffusion constant
            m = leaf_mgen_absorption( m, 's_cenorg', 0.05);  % it will not decay everywhere
            m.globalProps.mingradient=0.01; % this ensures that all polariser gradients are frozen
            m = leaf_mgen_conductivity( m, 'Polariser', 0.002);% diffusion constant WAS 0.001
            m = leaf_mgen_dilution( m, 'Polariser', false );% it will not dilute with growth
            m = leaf_mgen_absorption( m, 'Polariser', 0.1);  % it will not decay everywhere

               %%%%%%% The polariser
            if realtime>230 % From time 230  generate polariser
                id_proxorg_p = (id_prox_l >0.8);                                             % Eqn 2
                %  id_proxorg_p = id_prox_l;
                id_proxorg_l = id_proxorg_p * id_proxorg_a;
            end

            % switch on distorg with id_dist in the absence of id_lat
            % and enhance with dich in presence of cyc
            if abs(realtime - 230) <0.5*dt % At time 230 hrs
                if mutantnumber==3
                    id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l);
                else
                    id_distorg_p = 0.25* id_dist_l .* inh (100, id_lat_l)+ 0.1*(id_dich_l) .* id_dist_l .* id_cyc_l;         % Eqn 3 (used in production equation)
                end
                id_distorg_l = id_distorg_p * id_distorg_a;
                m.userdata.all_regions_ready=true;
            end
            
            if abs(realtime - 245) <0.5*dt %At 240 hrs
                %id_cenorg is activated by id_rim, id_lat and
                % id_div in absence of id_rad
                id_cenorg_p = 0.6*id_lat_l .* id_rim_l .* id_div_l ;                                   % Eqn 4 % CHECKED
                id_cenorg_l = id_cenorg_p * id_cenorg_a;
            end

            if mutantnumber==1
                m.mgen_production(:,polariser_i) = 0;
                disp('no polariser')
            elseif mutantnumber==2
                m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 - P .* (id_distorg_l+3*id_cenorg_l));
                disp('use distorg and cenorg to update polariser from the beginning')
            else
                m.mgen_production(:,polariser_i) = 0.1 * (id_proxorg_l + 1 - P .* (id_distorg_l+3*id_late_p.*id_cenorg_l));                   % Eqn 19 decay part of
                disp('update polariser without cenorg until 340')
            end

            %option for id_cyc being constitutive also see above realtime<250
            if mutantnumber==5 || mutantnumber==6
                id_cyc_p=ones(size(id_cyc_p));
                id_cyc_l=id_cyc_p.*id_cyc_a;
            end

            % s_dist is activated by id_dist
            m.mgen_production(:,s_dist_i) = 0.1 * id_dist_l.* inh (100, id_lat_l);          % Eqn 17

            % s_distorg is activated by id_distorg
            m.mgen_production(:,s_distorg_i) = 0.1 * id_distorg_l ;                         % Eqn 15 (but
            % note that distorg is set elsewhere) the 0.1 seems to be an error

            % s_cenorg is activated by id_cenorg
            m.mgen_production(:,s_cenorg_i) = 0.1 * id_cenorg_l;                            % Eqn 16



            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                id_cenorg_p = s_cenorg_l;                                                   % Eqn 11
                id_cenorg_l = id_cenorg_p .* id_cenorg_a;
                id_distorg_p = s_distorg_l;                                                 % Eqn 12
                id_distorg_l = id_distorg_p .* id_distorg_a;
                id_dist_p = s_dist_l;                                                       % Eqn 13
                id_dist_l = id_dist_p .* id_dist_a;
             end

            %             end
            % End Polariser

            % Start Gene Networks
            % id_rad is activated by id_cyc and id_dich at ALL TIMES
            id_rad_p = id_cyc_l +  0.3* id_dich_l;                                           % Eqn 1
            id_rad_l = id_rad_p * id_rad_a;

            if mutantnumber==4 || mutantnumber==6
                % option for id_rad being constitutive
                id_rad_p=ones(size(id_rad_p));
                id_rad_l=id_rad_p; % REMOVED this otherwise rad deficient looses constitutive .*id_rad_a;
            end
            % s_rad is activated by id_rad
            m.mgen_production(:,s_rad_i) = 0.1 * id_rad_l .* pro (0.5, id_tube_l);          % Eqn 14

            % I suspect that it is the order within this set of equations that matters because
            % cenorg depends on div and rim in the setup secton that also happen
            % at 240
            if abs(realtime - 240) <0.5*dt %At 240 hrs
                % continue with the initial regionalisation
                % replace [0,1] values with reals for quantitative growth

                %switch on id_div
                id_div_p=ones(size(id_div_p)).*inh(100, id_rad_l);                           % Eqn 5
                id_div_l=id_div_p.*id_div_a;

                %id_laterals is activated by id_div
                id_lts_p(:) = id_div_l;                                                      % Eqn 6
                id_lts_l=id_lts_p * id_lts_a;
                %id_cenorg is activated by id_rim, id_lat and
                % id_div in absence of id_rad
                id_cenorg_p = 0.6*id_lat_l .* id_rim_l .* id_div_l ;                                   % Eqn 4
                id_cenorg_l = id_cenorg_p * id_cenorg_a;
            end

            if abs(realtime - 250) <0.5*dt % At time 250 hrs
                %id_cyc and id_dich are inhibited by id_div in absence of id_rad.
                %This is to ensure that in a id_rad mutant,
                %id_cyc and id_dich are inactivated. (Also see constitutive cyc
                %below)
                id_cyc_p = id_cyc_l.* inh (4, id_div_l );                                    % Eqn 7
                id_cyc_l = id_cyc_p * id_cyc_a;

                id_dich_p = id_dich_l .* inh (4, id_div_l );                                 % Eqn 8
                id_dich_l = id_dich_p * id_dich_a;

                % one shot setup regionalising lateral petals
                id_lts_p=5*id_lts_l.* s_rad_l;                                               % Eqn 9
                id_lts_l=id_lts_p.*id_lts_a;
            end
            if abs(realtime - 340) <0.5*dt % At time 340 hrs
                % narrow domain of div expression with id_laterals and id_rad at ~ 14 days
                id_div_p = id_div_l .* inh (5, id_lts_l);                                   % Eqn 10
                id_div_l = id_div_p.*id_div_a;
            end
            % End Gene Networks

            % GROWTH MODEL BEGINS HERE
            if realtime >= 250 && realtime<570  % Between time 250 570
                % Compute growth rates

                Kpar=... % Eqn 260
                    0.013 ... % Background growth parallel to the polariser  Eqn 200
                    .* inh (0.2, id_prox_l)... %keeps base small                              Eqn 24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                    .* pro (0.4,id_tube_l .* inh (100, id_plt_l))... %promote growth of tube  Eqn 25
                    .* inh (1, id_rad_l .*id_lip_l .* inh(3, id_dich_l .* id_lat_l))... %prevent lip growing at edge of dorsals   Eqn 26
                    .* inh (1, id_rad_l .*id_plt_l .* inh(10, id_dich_l) .* inh (20, id_cyc_l .* inh (40, id_lat_l.^2)))... %prevent palate growing at edge of dorsals   Eqn 27
                    .* pro (0.3, id_cyc_l .* id_dtl_l  .* inh (0.5, id_dich_l))... %promote growth of lateral dorsal lobe   Eqn 28
                    .* pro (0.45, (id_cyc_l + 0.2* id_dich_l) .* id_plt_l)... %promote medial palate growth with CYC   Eqn 29
                    ...
                    .* pro (1.4, id_early_p .* id_lip_l .*inh (100, id_rad_l.* inh(100, id_dich_l.* id_lat_l)))... %form lower face   Eqn 30
                    .* pro (2.4, id_early_p .* id_div_l.*id_plt_l )... %make lower tube arch over  Eqn 31
                    .* inh (10,  id_early_p .* id_rim_l )... %inhibit rim to help with bending back    Eqn 32
                    ...
                    .* inh (0.5, id_late_p .* id_med_l.* id_lobe_l)... %reduce growth of midlobe   Eqn 38
                    .* inh (10,  id_late_p .* id_div_l .*id_cenorg_l.* inh(2, id_lpb_l).* pro (10, id_plt_l .* id_med_l))...% prevent lips protruding   Eqn 39
                    .* pro (0.2, id_late_p .* id_div_l .* id_plt_l)... %promote growth of palate   Eqn 40
                    .* inh (0.7, id_late_p .* id_lts_l .* id_lat_l .* (id_lip_l + id_plt_l))... %inhibit growth at edge of laterals   Eqn 41
                    .* pro (2.2, id_late_p .* id_lts_l .* id_med_l .* inh (0.5, id_lpb_l).* inh(4, id_lat_l) .*(id_lip_l + 0.3* id_plt_l));%  promote lateral growth   Eqn 42

%                 DKapar=1 ...
%                     .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
%                     .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
%                     .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35
                %AKapar=0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % bend back petals   Eqn 36

%                DKbpar=pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % bend dorsal lip forward  Eqn 37

                % Background growth normal to the polariser   Eqn 201

                Kper=... % Eqn 250
                    0.0075 ... % Background growth normal to the polariser   Eqn 201
                    .* inh (0.2, id_prox_l)... %keep base small   Eqn 43
                    .* pro (0.1, id_cyc_l  .* pro(1.5,id_lip_l))... % increase width of dorsal petal   Eqn 44
                    ...
                    .* inh(6, id_early_p .* id_lts_l.*id_med_l )... %  keep laterals narrow initially  Eqn 45
                    .* pro(2, id_early_p .* id_dist_l .* inh (20, id_lat_l))... %  widen distal lobe   Eqn 46
                    ...
                    .* pro (1,   id_late_p .* id_dist_l .* pro (1.2, (id_cyc_l + id_div_l)))... % increase width of distal lobe   Eqn 49
                    .* inh (0.3, id_late_p .* id_lobe_l .* id_med_l)... %keep medial lobe narrow   Eqn 50
                    .* inh (1.3, id_late_p .* id_div_l .* inh(2.5, id_lobe_l.* inh (2,id_lpb_l)).* pro(1, id_plt_l))...  %narrow ventral petals    Eqn 51
                    .* pro (0.2, id_late_p .* id_lts_l .* id_med_l .*  id_plt_l); %promote growth of lateral width   Eqn 52

%                 DKaper = pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
%                 DKbper = inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48

                % compute the growth rates
%                 kapar=Kpar .*DKapar ... % Eqn 300
%                     +0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % Eqn 301
%                 kbpar=Kpar .*DKbpar; % Eqn 310
%                 kaper=Kper .*DKaper; % Eqn 320
%                 kbper=Kper .*DKbper; % Eqn 330
%                 knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
                kapar=Kpar ...% Eqn 300
                    .* inh (1, id_dich_l.* id_lat_l  .* id_lpb_l)...                               % Eqn 33
                    .* inh (1, id_early_p .* (id_cyc_l + id_div_l) .*id_mlobe_l .* inh (5, id_dich_l))... %bend up distal lobes   Eqn 34
                    .* pro (1, id_early_p .*  id_div_l .* id_lpb_l.* inh (5, id_med_l))... % bend out lips   Eqn 35
                    +0.05* id_early_p .* id_rim_l .* ( 1.2*id_div_l + 0.3* id_lts_l.* id_med_l  + 0.5*(id_cyc_l +id_dich_l)); % Eqn 301
                kbpar=Kpar ... % Eqn 310
                    .*pro (2, id_dich_l .* id_lat_l  .* id_lpb_l); % Eqn 37
                kaper=Kper ... % Eqn 320
                    .* pro (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 47
                kbper=Kper ... % Eqn 330
                    .*inh (1, id_early_p .* id_div_l .* id_lpb_l.* inh (3, id_med_l));%bend out lips;   Eqn 48 
                knor =0.003; % thickness tracks model using Scaled USE KNOR(anti-curl) Eqn 305
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            end
        end

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        if realtime >= 250 && realtime<570  % Between time 250 570
                kapar_p=kapar;
                kbpar_p=kbpar;
                kaper_p=kaper;
                kbper_p=kbper; 
                knor_p =knor; 
        end
        % Growth factors cannot be negative.
        if realtime>250
            kapar_p = max( kapar_p, 0 );
            kbpar_p = max( kbpar_p, 0 );
            kaper_p = max( kaper_p, 0 );
            kbper_p = max( kbper_p, 0 );
        end
        % Reconstruct the old growth and bend morphogens.
        kpar_p = (kapar_p + kbpar_p)/2;
        kper_p = (kaper_p + kbper_p)/2;
        bendpar_p = kbpar_p - kpar_p;
        bendper_p = kbper_p - kper_p;

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


        if realtime>570 % finished growth
            % just increment time to allow flattened results to be saved
            kapar_p = 0;
            kbpar_p = 0;
            kaper_p = 0;
            kbper_p = 0;
        end

        % dissect the corolla for flattening
        %         if realtime==570 %(570>realtime-dt) && (570<realtime+dt)
        %                     lateral_protect=double(id_div_p>0.2 & id_div_p<0.536);%536);
        %                     f_seam4_p=lateral_protect;
        %                     dorsal_protect=(id_div_p<0.01);
        %                     f_seam4_p=dorsal_protect;
        %                     f_seam_p=f_seppetals_p + f_sepbase_p + f_seplobes2_p .* (f_seam3_p+lateral_protect);
        %                     m=leaf_set_seams(m,f_seam_p);
        %         elseif realtime==(570+dt)
        % USE this for separate parts
        f_seam_p(:)=0;
        f_seam_p=f_seppetals_p + f_sepbase_p + f_seplobes2_p ;
        %f_seam_p=f_seppetals_p + f_sepbase_p ;
        m=leaf_set_seams(m,f_seam_p);
        %         elseif realtime==(570+2*dt)
        %             f_seam_p=f_seppetals_p + f_sepbase_p + f_seplobes2_p ;
        %             m=leaf_set_seams(m,f_seam_p);
        %         end

        % Calculate the area, excluding the base.
        areaCells = any( id_prox_p( m.tricellvxs )==0, 2 );
        % These are the finite elements which have at least one vertex where
        % the id_prox morphogen is zero.

        nonBaseArea = sum( m.cellareas( areaCells ) );
        % This is the total area of these finite elements.

        fprintf( 1, 'Snapdragon area At %.3f, excluding the base = %.3f sq mm, including base = %.3f sq mm\n', ...
            realtime, nonBaseArea, sum( m.cellareas ) );

        % Calculate the area, excluding the base.
        nonBaseCells = any( id_prox_p( m.tricellvxs )==0, 2 );
        % These are the finite elements which have at least one vertex where
        % the id_prox morphogen is zero.
        nonBaseArea = sum( m.cellareas( nonBaseCells ) );
        % This is the total area of these finite elements.
        m.userdata.areas(m.globalDynamicProps.currentIter+1) = nonBaseArea;
        m.userdata.times(m.globalDynamicProps.currentIter+1) = realtime;

    end