summaryrefslogtreecommitdiff
path: root/modules/xcos/macros/getModelicaPath.sci
blob: 9e6d781b481b51411ff0ad9c15462fac75ea3b5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2010 - DIGITEO - Jérôme PICARD
// Copyright (C) 2010 - DIGITEO - Pierre MARECHAL

//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
//

function [modelica_path, modelica_directory] = getModelicaPath()
    // Return the Modelica directory path used by Xcos diagram containing Modelica blocks
    //
    // Calling Sequence
    //  [modelica_path, modelica_directory] = getModelicaPath()
    //
    // Parameters
    //  modelica_path:          Indicates path for generic modelica blocks, user
    //                          can add paths with %MODELICA_USER_LIBS for his own
    //                          blocks.
    //  modelica_directory:     output directory for generated modelica files
    //  %MODELICA_USER_LIBS:    string path global variable used by the user to
    //                          modify modelica_path. All paths should exist.

    // Init
    modelica_path      = "SCI/modules/scicos_blocks/macros/" + ["Electrical","Hydraulics"];
    modelica_directory = pathconvert(TMPDIR+"/modelica/",%T,%T);

    // user-defined %MODELICA_USER_LIBS
    global %MODELICA_USER_LIBS
    if exists("%MODELICA_USER_LIBS") & ~isempty(%MODELICA_USER_LIBS) then

        if type(%MODELICA_USER_LIBS)<>10 then
            error(msprintf(gettext("%s: Wrong type for %s variable: A string array expected.\n"),"getModelicaPath","%MODELICA_USER_LIBS"));
        end

        if or(~isdir(%MODELICA_USER_LIBS)) then
            error(msprintf(gettext("%s: All paths defined by %s variable must exist.\n"),"getModelicaPath","%MODELICA_USER_LIBS"));
        end

        // reshape %MODELICA_USER_LIBS to get a row vector
        %MODELICA_USER_LIBS = matrix(%MODELICA_USER_LIBS,[1 prod(size(%MODELICA_USER_LIBS))])

        // Remove duplicate paths
        %MODELICA_USER_LIBS = unique(%MODELICA_USER_LIBS);

        // Concatenate %MODELICA_USER_LIBS with modelica_path
        modelica_path = [ %MODELICA_USER_LIBS modelica_path ];
    end

    // create modelica directory if it doesn't exist
    if ~isdir(modelica_directory) & mkdir(modelica_directory)<>1 then
        error(msprintf(gettext("%s: The directory %s cannot been created, please check if you have write access on this directory.\n"),"getModelicaPath",modelica_directory));
    end

endfunction