File: waitexample.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (53 lines) | stat: -rw-r--r-- 1,351 bytes parent folder | download | duplicates (2)
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
// SuiteSparse/MATLAB_Tools/waitmex/waitexample.c
// waitmex, Copyright (c) 2007, Timothy A Davis. All Rights Reserved.
// SPDX-License-Identifier: BSD-3-clause

#include "waitmex.h"

/* The MATLAB equivalent of this function is give in waitex.m.
   Compile with:

    mex waitexample.c waitmex.c
 */

void useless (double *x) ;

void useless (double *x) { (*x)++ ; }

void mexFunction (int nargout, mxArray *pargout [ ],
    int nargin, const mxArray *pargin [ ])
{
    int i, j ;
    double x = 0 ;
    waitbar *h ;

    /* just like h = waitbar (0, 'Please wait...') in MATLAB */
    h = waitbar_create (0, "Please wait...") ;

    for (i = 0 ; i <= 100 ; i++)
    {
        if (i == 50)
        {
            /* just like waitbar (i/100, h, 'over half way there') in MATLAB */
            waitbar_update (((double) i) / 100., h, "over half way there") ;
        }
        else
        {
            /* just like waitbar (i/100, h) in MATLAB */
            waitbar_update (((double) i) / 100., h, NULL) ;
        }

        /* do some useless work */
        for (j = 0 ; j <= 10000000 ; j++) useless (&x) ;
    }
    if (nargout > 0)
    {
        /* return the handle to the waitbar, if requested */
        pargout [0] = waitbar_return (h) ;
    }
    else
    {
        /* just like close (h) in MATLAB */
        waitbar_destroy (h) ;
    }
}