# Case "define" then ^~~~^ Error: syntax error, unexpected case, expecting else or elseif or end

**URL:** <https://scilab.discourse.group/t/case-define-then-error-syntax-error-unexpected-case-expecting-else-or-elseif-or-end/460>\
**Category:** General usage\
**Created:** [April 11, 2024, 12:58pm UTC](https://scilab.discourse.group/t/case-define-then-error-syntax-error-unexpected-case-expecting-else-or-elseif-or-end/460 "2024-04-11T12:58:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vimsrocz](https://avatars.discourse-cdn.com/v4/letter/v/ed8c4c/32.png) [@Vimsrocz](https://scilab.discourse.group/u/Vimsrocz)\
**Post date:** [April 11, 2024, 12:58pm UTC](https://scilab.discourse.group/t/case-define-then-error-syntax-error-unexpected-case-expecting-else-or-elseif-or-end/460/1 "2024-04-11T12:58:04Z")

</div>

```auto
function [x, y, typ] = Kalman_Filter_IF(job, arg1, arg2)
    x = [];
    y = [];
    typ = [];
    getinput
    x0_set=[];
    covariance_matrix =[];
    
    select job
        // Initialize with mask parameters if any
        case "set" then
            x = arg1;
            graphics = arg1.graphics;
            exprs = graphics.exprs;
            model = arg1.model;
            
            if getInputFromSim==1 then
                exec("macros/Kalman_Filter_Utils.sci",-1);// Contains function declaration for this file
                title="Set Parameters";
                labels = ['Initial state [x_dot(velosity), x(position)] which is position in ECEF frame and velocity';'Covariance which gives the uncertainty at position and velocity']; // Changed 'Stiffness' to 'Covariance'
                 // In future we can add ;'Accelerations';'Orientations which is obation altitude control system
                types = list('vec', 2, 'mat', 2); // Changed 'vec' to 'mat' for Covariance
            // Create a dialog for getting user inputs
            while ~endLoop do
                // Initialize dialog for parameters and initial state
                [ok, Initial_state, covariance_matrix, exprs] = scicos_getvalue("Set Properties and State", labels, types, exprs);
                errMsg=[];
                // Check return // set conditions of the initial state as per meetings
                if ~ok then
                    // depends on what type of data we are having
                    if condition1 then // first condition of position and velocity
                        errMsg=[];
                    end 
                    
                    if condition2 then // second condition of velocity
                        errMsg=[];
                    end
                
                if isempty(errMsg)then 
                    [];// from here start working
                
                // Check parameters
                // You can add additional checks for input parameters here if needed
                
                // Accept inputs and save them
                if ok then
                    // Concatenate the covariance matrix to the state vector
                    model.state = [x0_set, covariance_matrix]; // Use the concatenation operator ":" for the matrix
                    graphics.exprs = exprs;
                    x.graphics = graphics;
                    x.model = model;
                    break;
                else
                    message("Failed to update block io");
                end
            end
            
        // Define block properties
        case "define" then
            // Create object
            model = scicos_model();
            // Provide name and type
            model.sim = list("Kalman_Filter_sim", 5);
            
            // Define inputs and outputs
            // One input with a variable-size "double" element
            model.in = [1]; // it's only z, 
            //it has at first position occupies which means at first position is 1, 1 indicates that only one input value, see wriiten notes to understand
            model.in2 = [1]; // the second dimension of I/P whcih means all the data enter has one dimension data for example just z axis data while if it was 2 than we have input data of x and y if there is 3 then x,y,z so on. each column represents specific data 
            model.intyp = 1;
            
            // One output with a single "double" element
            model.out = [2; 2];
            model.out2 = [1; 2];
            model.outtyp = 1;
            
                        // Set initial state
            model.state = [Initial_state; matrix(covariance_matrix, 4, 1)]; // Use the matrix concatenation function
            // For example: [initial_state; initial_covariance(:)]
            
            // Set default parameter
            model.rpar = covariance_matrix; // Use the covariance matrix as a parameter
            
            // Define block properties
            model.blocktype = 'c';
            model.dep_ut = [%t %f]; // what does %t and %f indicates?
            
            // Set block properties
            exprs = ["[0.0; 0.0]"; "[1.0]"]; // How do we get this value?
            x = standard_define([4 4], model, exprs);
            x.graphics.style = ["blockWithLabel;displayedLabel=Kalman_Filter"];
            //other cases other than set or define sections
         end
endfunction

```

Does anyone know what is the error in the syntax? I am trying to debug it?

---

<div class="post-metadata">

**Author:** ![philipp](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/philipp/32/53_2.png) [@philipp](https://scilab.discourse.group/u/philipp)\
**Post date:** [April 12, 2024, 11:23am UTC](https://scilab.discourse.group/t/case-define-then-error-syntax-error-unexpected-case-expecting-else-or-elseif-or-end/460/2 "2024-04-12T11:23:20Z")

</div>

Hi,

if I am not to wrong, all your loops (etc) boil down to something like this:

```auto
function [x, y, typ] = Kalman_Filter_IF(job, arg1, arg2)
    select job
        case "set" then
            if getInputFromSim==1 then
            while ~endLoop do
                if ~ok then
                    if condition1 then
                    end 
                    if condition2 then
                    end
                if isempty(errMsg)then 
                if ok then
                else
                end
            end
        case "define" then
        end
endfunction

```

May it be that some “end” statements are missing for

```auto
if getInputFromSim==1 then

```

and

```auto
if isempty(errMsg)then 

```

---

<div class="post-metadata">

**Author:** ![Vimsrocz](https://avatars.discourse-cdn.com/v4/letter/v/ed8c4c/32.png) [@Vimsrocz](https://scilab.discourse.group/u/Vimsrocz)\
**Post date:** [April 12, 2024, 12:34pm UTC](https://scilab.discourse.group/t/case-define-then-error-syntax-error-unexpected-case-expecting-else-or-elseif-or-end/460/3 "2024-04-12T12:34:05Z")

</div>

You are correct . I have resolve the graphics issue now input data type issue which is below

```auto
Building blocks...
at line 8 of function scicos_block ( C:\Program Files\scilab-2024.0.0\modules\scicos\macros\scicos_scicos\scicos_block.sci line 29 )
at line 29 of function standard_define ( C:\Program Files\scilab-2024.0.0\modules\scicos\macros\scicos_scicos\standard_define.sci line 50 )
at line 124 of function Kalman_Filter_IF ( C:\Users\Vims\Desktop\spacecraft-gnc-tbx\macros\Kalman_Filter_IF.sci line 124 )
at line 1 of executed string 
at line 78 of function tbx_build_blocks ( C:\Program Files\scilab-2024.0.0\modules\modules_manager\macros\tbx_build_blocks.sci line 90 )
at line 7 of function buildmacros ( C:\Users\Vims\Desktop\spacecraft-gnc-tbx\macros\buildmacros.sce line 10 )
at line 14 of executed file C:\Users\Vims\Desktop\spacecraft-gnc-tbx\macros\buildmacros.sce
at line 13 of function tbx_builder ( C:\Program Files\scilab-2024.0.0\modules\modules_manager\macros\tbx_builder.sci line 26 )
at line 40 of function tbx_builder_macros ( C:\Program Files\scilab-2024.0.0\modules\modules_manager\macros\tbx_builder_macros.sci line 55 )
at line 35 of function main_builder ( C:\Users\Vims\Desktop\spacecraft-gnc-tbx\builder.sce line 45 )
at line 54 of executed file C:\Users\Vims\Desktop\spacecraft-gnc-tbx\builder.sce

scicos_new: Wrong value for input argument #2: unable to set "model".

```

The Final code is here

```auto
function [x, y, typ] = Kalman_Filter_IF(job, arg1, arg2)
            funcprot(0)
    x = [];
    y = [];
    typ = [];
    getInputFromSim = 1;
    funcprot(0) // Use funcprot(0) to avoid this message it happen when we see inbuilt funcitons by system

    // getinput
    z = [3.1948799;-1.3840684;2.3774667]
    work=zeros(34,1)
    State = [3.1948799;-1.3840684;2.3774667]
    Covariance = [];
    
    
    select job
        // Initialize with mask parameters if any
    case "plot" then
        standard_draw(arg1);
    case "getinputs" then
        [x, y, typ] = standard_inputs(arg1);

    case "getoutputs" then
        [x, y, typ] = standard_outputs(arg1);

    case "getorigin" then
        [x, y] = standard_origin(arg1);
                        disp (graphics)
        case 'set'
                    // Assignments here comes after assignments of the execution with the "define" flag 
            x = arg1; // This line is essential, otherwise gives "Invalid index." error.
            graphics = arg1.graphics;
            exprs = graphics.exprs;
            model = arg1.model;
            
        if getInputFromSim == 1 then
                exec('macros/Kalman_Filter_Utils.sci', -1); // Not sure about this line in MATLAB, comment it if not necessary
                title = "Set Parameter";
                labels = ['Initial state [x_dot(velocity), x(position)] which is position in ECEF frame and velocity','Covariance which gives the uncertainty at position and velocity']; // Changed 'Stiffness' to 'Covariance'
                // In future we can add {'Accelerations', 'Orientations which is obation altitude control system'}
                types = list('mat', [2,2], 'mat', [2,2]); // Changed 'vec' to 'mat' for Covariance
                endLoop = %f;
            
                // Create a dialog for getting user inputs
            while ~endLoop do
                    // Initialize dialog for parameters and initial state
                    [ok, State, Covariance, exprs] = scicos_getvalue(title, labels, types, exprs);
                    errMsg = [];

                    // Check return set conditions of the initial state as per meetings
                    if ~ok then
                        // depends on what type of data we are having
                        if condition1 // first condition of position and velocity
                            errMsg = [];
                        end 
                        
                        if condition2 // second condition of velocity
                            errMsg = [];
                        end
                        
                    if isempty(errMsg) then
                        
                        [model.rpar, isError] = EncodeRpar_KF(model.rpar, State, Covariance);
                        
                        graphics.exprs = exprs;
                        x.graphics = graphics;
                        x.model = model;
                        endLoop = %t;
                    // Check parameters
                    // You can add additional checks for input parameters here if needed

                    // Accept inputs and save them
                     else
                        messagebox(errMsg);
                        error(errMsg, 20000);
                        endLoop = %f;
                    end
                    else
                    warning('Kalman_Filter_IF: Set: Cancel!');
                    endLoop = %t;
                end
            end
        else
            graphics.exprs = exprs;
            x.graphics = graphics;
            x.model = model;
        end

                        // Concatenate the covariance matrix to the state vector
                       // model.state = [State; Covariance(:)]; // Use the concatenation operator ":" for the matrix

        // Define block properties
        case 'define'then
            // Create object
            model = scicos_model();

            // Provide name and type
            model.sim = {'Kalman_Filter_sim', 5};

            // Define inputs and outputs
            // One input with a variable-size "double" element
            model.in = 1; // it's only z,
            // it has at first position occupies which means at first position is 1, 1 indicates that only one input value, see wriiten notes to understand
            model.in2 = 1; // the second dimension of I/P whcih means all the data enter has one dimension data for example just z axis data while if it was 2 than we have input data of x and y if there is 3 then x,y,z so on. each column represents specific data
            model.intyp = 1;

            // One output with a single "double" element
            model.out = [2; 2];
            model.out2 = [1; 2];
            model.outtyp = 1;
            // Set default parameter
            model.rpar= [Covariance(:)]; // Use the covariance matrix as a parameter

            // Set initial state
            model.state = [State; Covariance(:)]; // Use the matrix concatenation operator ":" to convert matrix to column vector
            // Define block properties
            model.blocktype = 'c';
            model.dep_ut = [%t,%f]; // what does %t and %f indicates? true and false

            // Set block properties
            exprs = ['[0.0; 0.0]', '[1.0]']; // How do we get this value?
            x = standard_define([4 4], model, exprs);
            x.graphics.style = ['blockWithLabel;displayedLabel=Kalman_Filter'];
            // other cases other than set or define sections
    end
endfunction

```

I think error is this line so currently working on it.

```auto
            exprs = ['[0.0; 0.0]', '[1.0]']; // How do we get this value?
            x = standard_define([4 4], model, exprs);

```

---

<div class="post-metadata">

**Author:** ![philipp](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/philipp/32/53_2.png) [@philipp](https://scilab.discourse.group/u/philipp)\
**Post date:** [April 12, 2024, 8:32pm UTC](https://scilab.discourse.group/t/case-define-then-error-syntax-error-unexpected-case-expecting-else-or-elseif-or-end/460/4 "2024-04-12T20:32:23Z")

</div>

mh…I am no scicos user at all, but a general hint:

If you use SciNotes you can use Ctrl-I to get correct indentings.

In the last code example the line

```auto
 if isempty(errMsg) then // line 61

```

gives the impression that an “end” is missing to close the if-statement at line 51.

Also further down below something similar appears.

After using

Ctrl+A // mark complete code  
Ctrl+I // apply correct indenting

the picture is completely different
