473,749 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

waitbar function error

25 New Member
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
Expand|Select|Wrap|Line Numbers
  1. /**************************************************************************
  2.  *  Waitbar function -- displays progress of lengthy calculations
  3.  *  -------------------------------------------------------------
  4.  *  Copyright (c) 2002  Quentin Spencer <qspencer@ieee.org>
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19.  *  02110-1301 USA
  20.  *
  21.  *
  22.  *************************************************************************/
  23.  
  24. #include <octave/oct.h>
  25. #if defined (HAVE_TERM_H)
  26. #  include <term.h>
  27. #elif defined (HAVE_TERMCAP_H)
  28. #  include <termcap.h>
  29. #endif
  30.  
  31. #define BUF_SIZE    256
  32. #define MAX_LEN        240
  33. #define DEFAULT_LEN    50
  34. #define    BAR_CHAR    '#'
  35. #define SPACING        3
  36.  
  37. static bool no_terminal=false;
  38.  
  39. DEFUN_DLD(waitbar, args, nargout,
  40. "waitbar(...);\n\
  41.  WAITBAR displays a text-based wait bar. This function\n\
  42.  is similar to the Matlab waitbar command, but it is\n\
  43.  a text, rather than graphical function.\n\n\
  44.  A typical usage of WAITBAR in a lengthy computation\n\
  45.  (inside a FOR loop, for example) is as follows:\n\n\
  46.  for i=1:1000\n\
  47.      ## computation\n\
  48.      waitbar(i/1000);\n\
  49.  end\n\n\
  50.  WAITBAR(X,TITLE), where 0 <= X <= 1, sets the position of\n\
  51.  the waitbar to the fractional length X. Values of X exactly\n\
  52.  equal to 0 or 1 clear the waitbar. The optional second\n\
  53.  argument TITLE sets the waitbar caption to TITLE.\n\n\
  54.  If Octave is running in a smart terminal, the width is\n\
  55.  automatically detected, and the title is displayed in the\n\
  56.  waitbar (and truncated if it is too long). Otherwise, the\n\
  57.  title is not displayed and the width is initialized to a\n\
  58.  default of 50 characters, or it can be set to N characters\n\
  59.  with WAITBAR(0,N). If no terminal is detected (such as when\n\
  60.  Octave is run in batch mode and output is redirected), no\n\
  61.  output is generated.\n\n\
  62.  For compatibility with the Matlab version of this function\n\
  63.  (which is graphical rather than text-based), additional\n\
  64.  arguments are ignored, but there are no guarantees of perfect\n\
  65.  compatibility.") 
  66. {
  67.   static char print_buf[BUF_SIZE];
  68.   static int n_chars_old;
  69.   static int pct_int_old;
  70.   static int length;
  71. #if defined(USE_TERM)
  72.   static char term_buffer[1024];
  73.   static char *begin_rv, *end_rv;
  74.   static int brvlen, ervlen, pct_pos;
  75.   static bool smart_term;
  76.   static bool newtitle = false;
  77.   static charMatrix title;
  78.   int j;
  79. #endif
  80.   static char *term;
  81.   static bool init;
  82.  
  83.   double pct;
  84.   int i;
  85.  
  86.   octave_value_list retval;
  87.   retval(0) = Matrix(0,0);
  88.   int nargin = args.length();
  89.   if (nargin < 1) {
  90.     print_usage ();
  91.     return retval;
  92.   }
  93.  
  94.   if(no_terminal)
  95.     return retval;
  96.  
  97.   pct    = args(0).double_value();
  98.   if(pct>1.0)    pct    = 1.0;        // to prevent overflow
  99.  
  100. #if defined(USE_TERM)
  101.   if(nargin==2 && args(1).is_string())
  102.     {
  103.       newtitle = true;
  104.       title = args(1).string_value();
  105.     }
  106.   if(nargin==3)
  107.     {
  108.       newtitle = true;
  109.       title = args(2).string_value();
  110.     }
  111. #endif
  112.  
  113.   if(pct==0.0 || pct==1.0)
  114.     {
  115.       init = true;
  116.       term = getenv("TERM");
  117.       if(!term)
  118.     {
  119.       no_terminal    = true;
  120.       return retval;
  121.     }
  122. #if defined (USE_TERM)
  123.       i = tgetnum("co");
  124.       smart_term = i ? true : false;
  125.       if(nargin==1 || args(1).is_string())
  126.     length = smart_term ? i-1 : DEFAULT_LEN;
  127. #else
  128.       if(nargin==1)
  129.         length = DEFAULT_LEN;
  130. #endif
  131.       else
  132.     if(nargin==2 && !(args(1).is_string()))
  133.     {
  134.       length    = args(1).int_value();
  135.       if(length>MAX_LEN)    length    = MAX_LEN;
  136.       if(length<=0)        length    = DEFAULT_LEN;
  137.     }
  138. #if defined (USE_TERM)
  139.       pct_pos = length/2-2;
  140.       if(smart_term)
  141.     {
  142.       // get terminal strings ("rv"="reverse video")
  143.       char* buf_ptr    = term_buffer;
  144.       begin_rv    = tgetstr("so", &buf_ptr);
  145.       end_rv    = tgetstr("se", &buf_ptr);
  146.       brvlen = 0;    buf_ptr = begin_rv;
  147.       while(buf_ptr[++brvlen]);
  148.       ervlen = 0;    buf_ptr = end_rv;
  149.       while(buf_ptr[++ervlen]);
  150.  
  151.       // initialize print buffer
  152.       for(i=0; i<BUF_SIZE; ++i)
  153.         print_buf[i]    = ' ';
  154.       print_buf[length+brvlen+ervlen+1] = '\r';
  155.       print_buf[length+brvlen+ervlen+2] = '\0';
  156.       for(i=0; i<brvlen; ++i)
  157.         print_buf[i]    = begin_rv[i];
  158.       for(i=0; i<ervlen; ++i)
  159.         print_buf[i+brvlen]    = end_rv[i];
  160.       fputs(print_buf,stdout);
  161.       if(title.length())
  162.         newtitle    = true;
  163.     }
  164.       else
  165.     {
  166. #endif
  167.       for(i=0; i<BUF_SIZE; ++i)
  168.         print_buf[i]    = ' ';
  169.       print_buf[length+8]    = '\r';
  170.       print_buf[length+9]    = '\0';
  171.       fputs(print_buf,stdout);
  172.       print_buf[0]        = '[';
  173.       print_buf[length+1]    = ']';
  174. #if defined (USE_TERM)
  175.     }
  176. #endif
  177.       n_chars_old    = 0;
  178.       fflush(stdout);
  179.       return retval;
  180.     }
  181.   else
  182.     {
  183.       // calculate position
  184.       int n_chars=(int)(pct*length+0.5);
  185.       int pct_int=(int)(pct*100.0+0.5);
  186.  
  187.       // check to see if we got this far without initialization
  188.       if(init==false)
  189.     {
  190.       Fwaitbar(octave_value(0.0),0);
  191.       fputs(print_buf,stdout);
  192.       fflush(stdout);
  193.     }
  194.  
  195.       // check to see of output needs to be updated
  196. #if !defined (USE_TERM)
  197.       if(n_chars!=n_chars_old || pct_int!=pct_int_old)
  198.     {
  199. #else
  200.       if(n_chars!=n_chars_old || pct_int!=pct_int_old || newtitle)
  201.     {
  202.       if(smart_term)
  203.         {
  204.           static char pct_str[5];
  205.           sprintf(pct_str,"%3i%%",pct_int);
  206.  
  207.           // Insert the title
  208.           if(newtitle)
  209.         {
  210.           pct_pos    = length-SPACING*2;
  211.           for(i=SPACING+brvlen; i<pct_pos+brvlen-SPACING;  ++i)
  212.             print_buf[ i>=n_chars_old+brvlen ? i+ervlen : i ] = ' ';
  213.           for(i=SPACING+brvlen, j=0; j<title.length(); ++i, ++j)
  214.             if(i<pct_pos+brvlen-SPACING)
  215.               print_buf[ i>=n_chars_old ? i+ervlen : i ] = title(0,j);
  216.           newtitle    = false;
  217.         }
  218.  
  219.           // Insert the percentage string
  220.           for(i=pct_pos+brvlen, j=0; j<4; ++i, ++j)
  221.         print_buf[ i>=n_chars_old+brvlen ? i+ervlen : i ] = pct_str[j];
  222.  
  223.           // Move print_buf characters
  224.           if(n_chars_old<n_chars)
  225.         for(i=n_chars_old+brvlen; i<n_chars+brvlen; ++i)
  226.           print_buf[i]    = print_buf[i+ervlen];
  227.           else
  228.         for(i=n_chars_old+brvlen-1; i>=n_chars+brvlen; --i)
  229.           print_buf[i+ervlen]    = print_buf[i];
  230.  
  231.           // Insert end of reverse video
  232.           for(i=n_chars+brvlen, j=0; j<ervlen; ++i, ++j)
  233.         print_buf[i]    = end_rv[j];
  234.         }
  235.       else
  236.         {
  237. #endif
  238.           if(n_chars>=n_chars_old)
  239.         for(int i=n_chars_old+1; i<=n_chars; ++i)
  240.           print_buf[i]    = BAR_CHAR;
  241.           else
  242.         for(int i=n_chars+1; i<=n_chars_old; ++i)
  243.           print_buf[i]    = ' ';
  244.           sprintf(&(print_buf[length+3])," %3i%%\r",pct_int);
  245. #if defined (USE_TERM)
  246.         }
  247. #endif
  248.       fputs(print_buf,stdout);
  249.       fflush(stdout);
  250.       n_chars_old    = n_chars;
  251.       pct_int_old    = pct_int;
  252.     }
  253.     }
  254.   return retval;
  255. }
Nov 2 '07 #1
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.
Nov 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
4964
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...
11
19029
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
2
9801
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...
4
2471
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?
14
1845
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.
2
5331
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
4
2166
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>
3
8649
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;...
9
3297
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...
0
9568
Oralloy
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...
0
9389
jinu1996
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...
1
9335
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,...
0
8257
agi2029
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...
1
6801
isladogs
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...
0
4709
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...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3320
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
3
2218
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.