summaryrefslogtreecommitdiff
path: root/js/Sinks/WFILE_f.js
blob: 96bf2ea2bad096bf5a3e2fa33d554efbd4388bab (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* autogenerated from "macros/Sinks/WFILE_f.sci" */
function WFILE_f() {
    WFILE_f.prototype.define = function WFILE_f() {
        this.in1 = 1;
        nin = sum(this.in1);
        frmt = "(7(e10.3,1x))";
        fname = "foo";
        lunit = 0;
        this.N = 2;
        model = scicos_model();
        model.sim = "writef";
        model.in1 = this.in1;
        model.evtin = 1;
        model.dstate = [[-1],[lunit],[zeros((nin+1)*this.N,1)]];
        model.ipar = [[length(fname)],[length(frmt)],[0],[this.N],[this._str2code[fname-1]],[this._str2code[frmt-1]]];
        model.blocktype = "d";
        model.dep_ut = [true,false];
        exprs = [[sci2exp(this.in1)],[fname],[frmt],[string(this.N)]];
        gr_i = [];
        this.x = standard_define([3,2],model,exprs,gr_i);
        return new BasicBlock(this.x);
    }
    WFILE_f.prototype.details = function WFILE_f() {
        return this.x;
    }
    WFILE_f.prototype.get = function WFILE_f() {
        var options = {
            in1:["Input Size",this.in1],
            fname1:["Output File Name",this.fname1],
            frmt1:["Output Format",this.frmt1],
            N:["Buffer Size",this.N],
        }
        return options;
    }
    WFILE_f.prototype.set = function WFILE_f() {
        this.in1 = parseFloat(arguments[0]["in1"])
        this.fname1 = parseFloat(arguments[0]["fname1"])
        this.frmt1 = parseFloat(arguments[0]["frmt1"])
        this.N = parseFloat(arguments[0]["N"])
        warnobsolete("WRITEC_f","6.0.0");
        warnMessage = msprintf(_("Feature %s is obsolete."),"WFILE_f");
        warnAdvise = msprintf(_("Please use %s instead."),"WRITEC_f");
        warnXcosMessage = msprintf("%s %s",warnMessage,warnAdvise);
        warnBlockByUID(arg1.model.label,warnXcosMessage);
        this.x = arg1;
        graphics = arg1.graphics;
        exprs = graphics.exprs;
        model = arg1.model;
        dstate = model.dstate;
        lunit = dstate[2-1];
        fname = exprs[2-1];
        frmt = exprs[3-1];
        while (true) {
            [ok,this.in1,this.fname1,this.frmt1,this.N,exprs] = scicos_getvalue([[msprintf("Set %s block parameters","WFILE_f")],[" "],["Write to output file"],[" "],["Write is done on:"],["  - A binary file if no format given"],["  - A formatted text file if a  format (Fortran type) is given"]],["Input Size","Output File Name","Output Format","Buffer Size"],list("vec",1,"str",1,"str",1,"vec",1),exprs);
            if (!ok) {
                break;
            }
            this.in1 = int(this.in1);
            nin = this.in1;
            this.fname1 = pathconvert(stripblanks(this.fname1),false,true);
            this.frmt1 = stripblanks(this.frmt1);
            if (lunit>0&&min(length(frmt),1)!=min(length(this.frmt1),1)) {
                block_parameter_error("Simulation running !!! You cannot switch<br />between formatted and unformatted when running","End current simulation first.");
                ok = false;
            } else if (lunit>0&&this.fname1!=fname) {
                block_parameter_error("You cannot modify \'Output File Name\' when running.","End current simulation first.");
                ok = false;
            } else if (this.fname1=="") {
                block_parameter_error("Wrong value for \'Output File Name\' parameter","You must provide a filename.");
                ok = false;
            } else if (fileparts(this.fname1)!="") {
                [pa,fn,ex] = fileparts(this.fname1);
                if (!this.isdir[pa-1]) {
                    block_parameter_error(msprintf("Wrong value for \'%s\' parameter.","Output File Name"),msprintf("Directory \'%s\' does not exist",pa));
                    ok = false;
                }
            } else if (this.frmt1!=""&&(part(this.frmt1,1)!="("||part(this.frmt1,length(this.frmt1))!=")")) {
                block_parameter_error(msprintf("Wrong value for \'%s\' parameter: %s.","Input Format",this.frmt1),"You must enclose the format\'s string between parentheses.");
                ok = false;
            } else if (this.N<2) {
                block_parameter_error(msprintf("Wrong value for \'%s\' parameter: %d.","Buffer Size",this.N),"Must be greater than 1.");
                ok = false;
            } else if (this.in1<=0) {
                block_parameter_error(msprintf("Wrong value for \'%s\' parameter: %d.","Input Size",this.in1),"Strictly positive integer expected.");
                ok = false;
            }
            if (ok) {
                ipar = [[length(this.fname1)],[length(this.frmt1)],[0],[this.N],[this._str2code[this.fname1-1]],[this._str2code[this.frmt1-1]]];
                if (prod(size(dstate))!=(nin+1)*this.N+2) {
                    dstate = [[-1],[lunit],[zeros((nin+1)*this.N,1)]];
                }
                model.in1 = nin;
                model.dstate = dstate;
                model.ipar = ipar;
                model.dep_ut = [true,false];
                graphics.exprs = exprs;
                this.x.graphics = graphics;
                this.x.model = model;
                break;
            }
        }
        return new BasicBlock(this.x);
    }
}