Hello,
I found this waitbar functioning pgm in a forum which does the same work as a matlab waitbar. However this pgm has an error and i cudnot figure it out. Can anyone pls correct it.
Thanks,
Prads -
/**************************************************************************
-
* Waitbar function -- displays progress of lengthy calculations
-
* -------------------------------------------------------------
-
* Copyright (c) 2002 Quentin Spencer <qspencer@ieee.org>
-
*
-
* This library is free software; you can redistribute it and/or
-
* modify it under the terms of the GNU Library General Public
-
* License as published by the Free Software Foundation; either
-
* version 2 of the License, or (at your option) any later version.
-
*
-
* This library is distributed in the hope that it will be useful,
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-
* Library General Public License for more details.
-
*
-
* You should have received a copy of the GNU Library General Public
-
* License along with this library; if not, write to the Free
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-
* 02110-1301 USA
-
*
-
*
-
*************************************************************************/
-
-
#include <octave/oct.h>
-
#if defined (HAVE_TERM_H)
-
# include <term.h>
-
#elif defined (HAVE_TERMCAP_H)
-
# include <termcap.h>
-
#endif
-
-
#define BUF_SIZE 256
-
#define MAX_LEN 240
-
#define DEFAULT_LEN 50
-
#define BAR_CHAR '#'
-
#define SPACING 3
-
-
static bool no_terminal=false;
-
-
DEFUN_DLD(waitbar, args, nargout,
-
"waitbar(...);\n\
-
WAITBAR displays a text-based wait bar. This function\n\
-
is similar to the Matlab waitbar command, but it is\n\
-
a text, rather than graphical function.\n\n\
-
A typical usage of WAITBAR in a lengthy computation\n\
-
(inside a FOR loop, for example) is as follows:\n\n\
-
for i=1:1000\n\
-
## computation\n\
-
waitbar(i/1000);\n\
-
end\n\n\
-
WAITBAR(X,TITLE), where 0 <= X <= 1, sets the position of\n\
-
the waitbar to the fractional length X. Values of X exactly\n\
-
equal to 0 or 1 clear the waitbar. The optional second\n\
-
argument TITLE sets the waitbar caption to TITLE.\n\n\
-
If Octave is running in a smart terminal, the width is\n\
-
automatically detected, and the title is displayed in the\n\
-
waitbar (and truncated if it is too long). Otherwise, the\n\
-
title is not displayed and the width is initialized to a\n\
-
default of 50 characters, or it can be set to N characters\n\
-
with WAITBAR(0,N). If no terminal is detected (such as when\n\
-
Octave is run in batch mode and output is redirected), no\n\
-
output is generated.\n\n\
-
For compatibility with the Matlab version of this function\n\
-
(which is graphical rather than text-based), additional\n\
-
arguments are ignored, but there are no guarantees of perfect\n\
-
compatibility.")
-
{
-
static char print_buf[BUF_SIZE];
-
static int n_chars_old;
-
static int pct_int_old;
-
static int length;
-
#if defined(USE_TERM)
-
static char term_buffer[1024];
-
static char *begin_rv, *end_rv;
-
static int brvlen, ervlen, pct_pos;
-
static bool smart_term;
-
static bool newtitle = false;
-
static charMatrix title;
-
int j;
-
#endif
-
static char *term;
-
static bool init;
-
-
double pct;
-
int i;
-
-
octave_value_list retval;
-
retval(0) = Matrix(0,0);
-
int nargin = args.length();
-
if (nargin < 1) {
-
print_usage ();
-
return retval;
-
}
-
-
if(no_terminal)
-
return retval;
-
-
pct = args(0).double_value();
-
if(pct>1.0) pct = 1.0; // to prevent overflow
-
-
#if defined(USE_TERM)
-
if(nargin==2 && args(1).is_string())
-
{
-
newtitle = true;
-
title = args(1).string_value();
-
}
-
if(nargin==3)
-
{
-
newtitle = true;
-
title = args(2).string_value();
-
}
-
#endif
-
-
if(pct==0.0 || pct==1.0)
-
{
-
init = true;
-
term = getenv("TERM");
-
if(!term)
-
{
-
no_terminal = true;
-
return retval;
-
}
-
#if defined (USE_TERM)
-
i = tgetnum("co");
-
smart_term = i ? true : false;
-
if(nargin==1 || args(1).is_string())
-
length = smart_term ? i-1 : DEFAULT_LEN;
-
#else
-
if(nargin==1)
-
length = DEFAULT_LEN;
-
#endif
-
else
-
if(nargin==2 && !(args(1).is_string()))
-
{
-
length = args(1).int_value();
-
if(length>MAX_LEN) length = MAX_LEN;
-
if(length<=0) length = DEFAULT_LEN;
-
}
-
#if defined (USE_TERM)
-
pct_pos = length/2-2;
-
if(smart_term)
-
{
-
// get terminal strings ("rv"="reverse video")
-
char* buf_ptr = term_buffer;
-
begin_rv = tgetstr("so", &buf_ptr);
-
end_rv = tgetstr("se", &buf_ptr);
-
brvlen = 0; buf_ptr = begin_rv;
-
while(buf_ptr[++brvlen]);
-
ervlen = 0; buf_ptr = end_rv;
-
while(buf_ptr[++ervlen]);
-
-
// initialize print buffer
-
for(i=0; i<BUF_SIZE; ++i)
-
print_buf[i] = ' ';
-
print_buf[length+brvlen+ervlen+1] = '\r';
-
print_buf[length+brvlen+ervlen+2] = '\0';
-
for(i=0; i<brvlen; ++i)
-
print_buf[i] = begin_rv[i];
-
for(i=0; i<ervlen; ++i)
-
print_buf[i+brvlen] = end_rv[i];
-
fputs(print_buf,stdout);
-
if(title.length())
-
newtitle = true;
-
}
-
else
-
{
-
#endif
-
for(i=0; i<BUF_SIZE; ++i)
-
print_buf[i] = ' ';
-
print_buf[length+8] = '\r';
-
print_buf[length+9] = '\0';
-
fputs(print_buf,stdout);
-
print_buf[0] = '[';
-
print_buf[length+1] = ']';
-
#if defined (USE_TERM)
-
}
-
#endif
-
n_chars_old = 0;
-
fflush(stdout);
-
return retval;
-
}
-
else
-
{
-
// calculate position
-
int n_chars=(int)(pct*length+0.5);
-
int pct_int=(int)(pct*100.0+0.5);
-
-
// check to see if we got this far without initialization
-
if(init==false)
-
{
-
Fwaitbar(octave_value(0.0),0);
-
fputs(print_buf,stdout);
-
fflush(stdout);
-
}
-
-
// check to see of output needs to be updated
-
#if !defined (USE_TERM)
-
if(n_chars!=n_chars_old || pct_int!=pct_int_old)
-
{
-
#else
-
if(n_chars!=n_chars_old || pct_int!=pct_int_old || newtitle)
-
{
-
if(smart_term)
-
{
-
static char pct_str[5];
-
sprintf(pct_str,"%3i%%",pct_int);
-
-
// Insert the title
-
if(newtitle)
-
{
-
pct_pos = length-SPACING*2;
-
for(i=SPACING+brvlen; i<pct_pos+brvlen-SPACING; ++i)
-
print_buf[ i>=n_chars_old+brvlen ? i+ervlen : i ] = ' ';
-
for(i=SPACING+brvlen, j=0; j<title.length(); ++i, ++j)
-
if(i<pct_pos+brvlen-SPACING)
-
print_buf[ i>=n_chars_old ? i+ervlen : i ] = title(0,j);
-
newtitle = false;
-
}
-
-
// Insert the percentage string
-
for(i=pct_pos+brvlen, j=0; j<4; ++i, ++j)
-
print_buf[ i>=n_chars_old+brvlen ? i+ervlen : i ] = pct_str[j];
-
-
// Move print_buf characters
-
if(n_chars_old<n_chars)
-
for(i=n_chars_old+brvlen; i<n_chars+brvlen; ++i)
-
print_buf[i] = print_buf[i+ervlen];
-
else
-
for(i=n_chars_old+brvlen-1; i>=n_chars+brvlen; --i)
-
print_buf[i+ervlen] = print_buf[i];
-
-
// Insert end of reverse video
-
for(i=n_chars+brvlen, j=0; j<ervlen; ++i, ++j)
-
print_buf[i] = end_rv[j];
-
}
-
else
-
{
-
#endif
-
if(n_chars>=n_chars_old)
-
for(int i=n_chars_old+1; i<=n_chars; ++i)
-
print_buf[i] = BAR_CHAR;
-
else
-
for(int i=n_chars+1; i<=n_chars_old; ++i)
-
print_buf[i] = ' ';
-
sprintf(&(print_buf[length+3])," %3i%%\r",pct_int);
-
#if defined (USE_TERM)
-
}
-
#endif
-
fputs(print_buf,stdout);
-
fflush(stdout);
-
n_chars_old = n_chars;
-
pct_int_old = pct_int;
-
}
-
}
-
return retval;
-
}
1 1590 Banfa 9,065
Recognized Expert Moderator Expert
However this pgm has an error and i cudnot figure it out.
This doesn't appear to be a program, I see no main.
Also if you want help then rather than stating that the code has an error I suggest that you list the errors and the expected/observed behaviour.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my webserver runs that part of the
script (see attached file, snippet.php), though, it doesn't go through.
I don't get an error message or anything...it just returns a "1"
(whereas it should return a "0") as far as I can tell. I have read the
PHP...
|
by: John Collyer |
last post by:
Hi,
In assembly language you can use a lookup table to call functions.
1. Lookup function address in table
2. Call the function
Like:
CALL FUNCTION
|
by: Chuck Martin |
last post by:
I am having a most frustrating problem that references, web searches,
and other resources are no help so far in solving. Basically, I'm trying
to design a pop-up window to be called with a funciton in a link. that
function can have parameters for URL and window name passed to it.
This works peachy in Firefox (1.0). With IE 6 (6.0.29) on two separate
computers, I get an "onject expected" error. Going to the MS-based
debugger just tells me...
|
by: atv |
last post by:
Whatis the proper way to handle errors from function calls?
For example, i normally have a main function, with calls to mine
or c functions. Should i check for errors in the functions called
themselves, or should i return a code to main and handle the error
there?
If i don't return them to main, except for the structure, what
use is the main function except for calling functions?
|
by: Mr Newbie |
last post by:
I am often in the situation where I want to act on the result of a function,
but a simple boolean is not enough. For example, I may have a function
called
isAuthorised ( User, Action ) as ?????
OK, this function may return a boolean, and if this is true, then no message
back is really required, but if it fails then some supporting message needs
to be returned to the calling code. As I see it there are a few options.
| |
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2
Ask on python-list@python.org .
- Josiah
|
by: prads |
last post by:
Hello,
this waitbar function (similar to the one in matlab) in C++ pops an error. Pls correct the error for me.
Thanks,
prads
<code>
#include <octave/oct.h>
#if defined (HAVE_TERM_H)
# include <term.h>
|
by: suganya |
last post by:
Hi
Some professionals already has developed the project using menu. In my company, they have given me task to clear the error in that. It is a script file named as "menubarAPI4.js" which is kept inside the folder "menu_script".
The following is the code in this file.
var menuOffsetTop=menuOffsetLeft=submenuOffsetTop=submenuOffsetLeft=submenuOffsetRight=0;
var Doc=this.document;var standards=Doc.createElement&&Doc.createTextNode?1:0;...
|
by: MrDeej |
last post by:
Hello guys!
We have an SQL server which sometimes makes timeouts and connection errors. And we have an function witch writes and updates data in 2 tables on this server. When the SQL server error appears it, in 99%, of the cases, works if we just press the play button in VBA debug. Therefor we have maked an error handling which just tryes again.
However, as this error handling is difficult to test because of maybe 1 or 2 errors a day, we...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |